利用jsoncpp+curl+opencv从服务器上解析到下载到显示图片

#include<iostream>
#include<fstream>
#include"json.h"
#include "opencv2/opencv.hpp"

using namespace cv;
using namespace std;

void get_json_txt()
{
	system("curl \"http://192.168.8.3:3000/getPhotoWallLogin?user=steve02&key=670b14728ad9902aecba32e22fa4f6bd&screenCode=sc08\" -o json_data.txt");
}

Json::Value get_json_array()
{
	ifstream file("json_data.txt");
	if (!file)
	{
		cout << "Open file the json_dat.txt fail!!!" << endl;
		getchar();
		return -1;
	}

	Json::Value root;
	Json::Reader reader;

	if (!reader.parse(file, root, false))
	{
		cout << "Plz check your url make sure you can  contact your host" << endl;
		getchar();
		return -1;
	}

	return root;
}

vector<string> get_url(Json::Value root)
{
	vector<string> pic_url;
	for (int i = 0; i < 4; ++i)
	{
		pic_url.push_back(root["info"][i]["originalInfo"]["url"].asString());
	}

	//for (auto s : pic_url)
	//	cout << s << endl;

	return pic_url;
}

void MultiImage_OneWin(const std::string& MultiShow_WinName, const vector<Mat>& SrcImg_V, CvSize SubPlot, CvSize ImgMax_Size);

int main()
{
	string pic1_photoId_index(" ");
	string pic2_photoId_index(" ");
	string pic3_photoId_index(" ");
	string pic4_photoId_index(" ");
	while (1)
	{

		get_json_txt();

		Json::Value root;
		root = get_json_array();
		cout << root.size();

		get_url(root);
		int index[4] = { 0, 1, 2, 3 };

		cout << "---------------------------------------------------" << endl;
		cout << "上次图片1的id--->" << pic1_photoId_index << endl;
		cout << "上次图片2的id--->" << pic2_photoId_index << endl;
		cout << "上次图片1的id--->" << pic3_photoId_index << endl;
		cout << "上次图片2的id--->" << pic4_photoId_index << endl;
		string pic1 = root["info"][index[0]]["photoId"].asString();
		string pic2 = root["info"][index[1]]["photoId"].asString();
		string pic3 = root["info"][index[2]]["photoId"].asString();
		string pic4 = root["info"][index[3]]["photoId"].asString();

		cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
		cout << "图片id1--------->" << pic1 << endl;
		cout << "图片id2--------->" << pic2 << endl;
		cout << "图片id3--------->" << pic1 << endl;
		cout << "图片id4--------->" << pic2 << endl;
		cout << "---------------------------------------------------" << endl;

		//if (pic1 != pic1_photoId_index || pic2 != pic2_photoId_index || pic3 != pic3_photoId_index || pic4 != pic4_photoId_index)
		{

			pic1_photoId_index = pic1;
			pic2_photoId_index = pic2;
			pic3_photoId_index = pic3;
			pic4_photoId_index = pic4;

			vector<string>pic_url;
			pic_url = get_url(root);
			string http = root["photoServerIp"].asString();
			cout << pic_url.size() << endl;
			string command1 = "curl -o 1.jpg " + http + "/" + pic_url[0];
			string command2 = "curl -o 2.jpg " + http + "/" + pic_url[1];
			string command3 = "curl -o 3.jpg " + http + "/" + pic_url[2];
			string command4 = "curl -o 4.jpg " + http + "/" + pic_url[3];
			cout << command1 << endl;
			cout << command2 << endl;
			cout << command3 << endl;
			cout << command4 << endl;

			system(command1.c_str());
			system(command2.c_str());
			system(command3.c_str());
			system(command4.c_str());
		}

		vector<Mat> imgs(4);
		imgs[0] = imread("1.jpg");
		imgs[1] = imread("2.jpg");
		imgs[2] = imread("3.jpg");
		imgs[3] = imread("4.jpg");
		MultiImage_OneWin("Multiple Images", imgs, cvSize(2, 2), cvSize(400, 280));
	}
}

void MultiImage_OneWin(const std::string& MultiShow_WinName, const vector<Mat>& SrcImg_V, CvSize SubPlot, CvSize ImgMax_Size)
{
	//Reference : http://blog.csdn.net/yangyangyang20092010/article/details/21740373
	//Window's image
	Mat Disp_Img;
	//Width of source image
	CvSize Img_OrigSize = cvSize(SrcImg_V[0].cols, SrcImg_V[0].rows);

	//******************** Set the width for displayed image ********************//
	//Width vs height ratio of source image
	float WH_Ratio_Orig = Img_OrigSize.width / (float)Img_OrigSize.height;
	CvSize ImgDisp_Size = cvSize(100, 100);
	//if (Img_OrigSize.width > ImgMax_Size.width)
	//	ImgDisp_Size = cvSize(ImgMax_Size.width, (int)ImgMax_Size.width / WH_Ratio_Orig);
	//else if (Img_OrigSize.height > ImgMax_Size.height)
	//	ImgDisp_Size = cvSize((int)ImgMax_Size.height*WH_Ratio_Orig, ImgMax_Size.height);
	//else
	ImgDisp_Size = cvSize(Img_OrigSize.width, Img_OrigSize.height);

	//******************** Check Image numbers with Subplot layout ********************//
	int Img_Num = (int)SrcImg_V.size();
	if (Img_Num > SubPlot.width * SubPlot.height)
	{
		cout << "Your SubPlot Setting is too small !" << endl;
		exit(0);
	}

	//******************** Blank setting ********************//
	CvSize DispBlank_Edge = cvSize(80, 60);
	CvSize DispBlank_Gap = cvSize(15, 15);
	//******************** Size for Window ********************//
	Disp_Img.create(Size(ImgDisp_Size.width*SubPlot.width + DispBlank_Edge.width + (SubPlot.width - 1)*DispBlank_Gap.width,
		ImgDisp_Size.height*SubPlot.height + DispBlank_Edge.height + (SubPlot.height - 1)*DispBlank_Gap.height), CV_8UC3);
	Disp_Img.setTo(0);//Background
	//Left top position for each image
	int EdgeBlank_X = (Disp_Img.cols - (ImgDisp_Size.width*SubPlot.width + (SubPlot.width - 1)*DispBlank_Gap.width)) / 2;
	int EdgeBlank_Y = (Disp_Img.rows - (ImgDisp_Size.height*SubPlot.height + (SubPlot.height - 1)*DispBlank_Gap.height)) / 2;
	CvPoint LT_BasePos = cvPoint(EdgeBlank_X, EdgeBlank_Y);
	CvPoint LT_Pos = LT_BasePos;

	//Display all images
	for (int i = 0; i < Img_Num; i++)
	{
		//Obtain the left top position
		if ((i%SubPlot.width == 0) && (LT_Pos.x != LT_BasePos.x))
		{
			LT_Pos.x = LT_BasePos.x;
			LT_Pos.y += (DispBlank_Gap.height + ImgDisp_Size.height);
		}
		//Writting each to Window's Image
		Mat imgROI = Disp_Img(Rect(LT_Pos.x, LT_Pos.y, ImgDisp_Size.width, ImgDisp_Size.height));
		resize(SrcImg_V[i], imgROI, Size(ImgDisp_Size.width, ImgDisp_Size.height));

		LT_Pos.x += (DispBlank_Gap.width + ImgDisp_Size.width);
	}

	//Get the screen size of computer
	//int Scree_W = GetSystemMetrics(SM_CXSCREEN);
	//int Scree_H = GetSystemMetrics(SM_CYSCREEN);
	int Scree_W = 1920;
	int Scree_H = 1080;

	//namedWindow("pic_viewer", CV_WINDOW_NORMAL);
	//setWindowProperty("pic_viewer", CV_WND_PROP_FULLSCREEN, CV_WINDOW_FULLSCREEN);

	cvNamedWindow(MultiShow_WinName.c_str(), CV_WINDOW_NORMAL);
	//cvMoveWindow(MultiShow_WinName.c_str(), (Scree_W - Disp_Img.cols) / 2, (Scree_H - Disp_Img.rows) / 2);//Centralize the window
	setWindowProperty(MultiShow_WinName, CV_WND_PROP_FULLSCREEN, CV_WINDOW_FULLSCREEN);
	cvShowImage(MultiShow_WinName.c_str(), &(IplImage(Disp_Img)));
	cvWaitKey(100);
	//cvDestroyWindow(MultiShow_WinName.c_str());
}

时间: 2024-08-11 03:28:51

利用jsoncpp+curl+opencv从服务器上解析到下载到显示图片的相关文章

Spring MVC 上传、下载、显示图片

通过这篇文章你可以了解到: 使用 SpringMVC 框架,上传图片,并将上传的图片保存到文件系统,并将图片路径持久化到数据库 在 JSP 页面上实现显示图片.下载图片 [TOC] 1. 准备工作 首先我们需要准备好开发环境,本文测试环境是 SSM(Spring 4.3.9 + SpringMVC 4.3.9 + MyBatis 3.4.4) ,数据库为 MySQL 5.5,数据库连接池 C3P0 0.9.5.2,构建包 Maven 3.5.0,Tomcat 8.5. 限于篇幅原因,关于 SSM

模拟php curl向远程服务器上传文件

test.php: <?php header('content-type:text/html;charset=utf8'); $ch = curl_init(); //加@符号curl就会把它当成是文件上传处理 $data = array('img'=>'@'. dirname(__FILE__).'/img/1.jpg'); curl_setopt($ch,CURLOPT_URL,"http://localhost:8088/curl/get_img.php"); cur

windows、linux通过ftp从ftp服务器上传和下载

最近需要用到文件的上传和下载,查看我们使用的系统,发现有一个进程为t_ftpd,怀疑其为一个ftp的守护进程,于是想要用ftp的方式实现. 在windows上使用bat脚本的方式实现: 首先写一个bat脚本: download.bat @echo off ftp -s:E:\Sylixos\SylixOS_Qt\build-TCWareWigget-Desktop_Qt_5_7_1_MinGW_32bit-Debug\debug\ftp\ftp.txt 这样就会调用ftp.txt文件 ftp.t

利用 qshell qupload 批量迁移服务器上的网站图片到七牛云

qshell qupload 官方迁移文档 https://developer.qiniu.com/kodo/kb/1685/using-qshell-synchronize-directories https://github.com/qiniu/qshell/blob/master/docs/qupload.md 按照步骤执行命令.会在 ~/.qshell/ 目录下生成 account.json文件.cat 一下,就明白了,是登陆的账号密码了. 配置文件 { "src_dir":&

Spring中利用组件实现从FTP服务器上传/下载文件

FtpUtil.java import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import org.apache.commons.ne

在SecureCRT上,使用命令行从远程服务器上传或者下载文件

引言: 在服务器上,一般都会通过命令行来进行访问.对于上传或者下载文件的需求,除了使用filezilla之类的工具之外,还可以使用rz/sz来完成类似操作. 1.  SecureCRT SecureCRT是一款支持SSH(SSH1和SSH2)的终端仿真程序,简单地说是Windows下登录UNIX或Linux服务器主机的软件. 一般的运维或者开发人员都是使用这些工具来远程登录服务器,完成相应操作. 2.  上传或者下载文件需求 一般服务器如果开发了21端口,并支持ftp协议,则可以使用filezi

利用putty实现文件在linux上传和下载

利用putty实现文件上传和下载:1.打开windows命令提示符窗口d:(putty在d盘下)cd putty(pscp.exe所在目录)2:上传(主要利用pscp程序)pscp d:/jdk-8u111-linux-x64.tar.gz [email protected]:/usr/javafiles/pscp d:/demo.war [email protected]:/usr/javafiles/3:下载(主要利用pscp程序)pscp [email protected]:/usr/ja

Linux 如何通过某一台服务器调用执行多台远程服务器上的脚本,结果显示在本地?

现在都流行自动化运维了,可能目前技术不够,很多自动化工具还不怎么会用,所以本次只是通过ssh来实现功能. 说明:自己写的一个简单脚本,只是实现了基础功能,还有待优化. 一共三台机器: master:192.168.4.91 slave1:192.168.4.45 slave2:192.168.4.96 在slave1上远程执行master.slave2上的脚本,结果显示或者放到本地.当然多台系统也行. 一.脚本功能主要是监控系统的一些资源,像cpu,磁盘,网速等等.System_Load.sh

centos服务器上git clone下载加速

最近在服务器上直接git clone github上的仓库,下载速度只有十几KB,简直不要太慢! 网上搜了一些加速的,自己于是写了下面的总结. 1. nslookup命令 如果执行这个命令找不到,请先执行: yum -y install bind-utils 然后执行下面两条命令 nslookup github.global.ssl.fastly.Net nslookup github.com 如图: 2. 修改hosts文件 写上对应的IP X.X.X.X http://global-ssl.