#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.youkuaiyun.com/yangyangyang20092010/article/details/21740373
//Window's image
Mat Disp_Img;
//Width of source image
CvSize Img_OrigSiz
利用jsoncpp+curl+opencv从服务器上解析到下载到显示图片
最新推荐文章于 2024-03-10 10:38:55 发布