video.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. #include <opencv2/viz/vizcore.hpp>
  2. #include <opencv2/calib3d.hpp>
  3. #include <iostream>
  4. #include <fstream>
  5. #include <opencv2/cnn_3dobj.hpp>
  6. #include <opencv2/features2d.hpp>
  7. #include <iomanip>
  8. using namespace cv;
  9. using namespace std;
  10. using namespace cv::cnn_3dobj;
  11. /**
  12. * @function listDir
  13. * @brief Making all files names under a directory into a list
  14. */
  15. static void listDir(const char *path, std::vector<String>& files, bool r)
  16. {
  17. DIR *pDir;
  18. struct dirent *ent;
  19. char childpath[512];
  20. pDir = opendir(path);
  21. memset(childpath, 0, sizeof(childpath));
  22. while ((ent = readdir(pDir)) != NULL)
  23. {
  24. if (ent->d_type & DT_DIR)
  25. {
  26. if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0)
  27. {
  28. continue;
  29. }
  30. if(r)
  31. {
  32. sprintf(childpath, "%s/%s", path, ent->d_name);
  33. listDir(childpath,files,false);
  34. }
  35. }
  36. else
  37. {
  38. files.push_back(ent->d_name);
  39. }
  40. }
  41. sort(files.begin(),files.end());
  42. };
  43. /**
  44. * @function cvcloud_load
  45. * @brief load bunny.ply
  46. */
  47. static Mat cvcloud_load(Mat feature_reference)
  48. {
  49. Mat cloud(1, feature_reference.rows, CV_32FC3);
  50. Point3f* data = cloud.ptr<cv::Point3f>();
  51. for(int i = 0; i < feature_reference.rows; ++i)
  52. {
  53. data[i].x = feature_reference.at<float>(i,0);
  54. data[i].y = feature_reference.at<float>(i,1);
  55. data[i].z = feature_reference.at<float>(i,2);
  56. }
  57. cloud *= 5.0f;
  58. return cloud;
  59. }
  60. /**
  61. * @function main
  62. */
  63. int main(int argc, char **argv)
  64. {
  65. const String keys = "{help | | This sample will extract featrues from reference images and target image for classification. You can add a mean_file if there little variance in data such as human faces, otherwise it is not so useful}"
  66. "{src_dir | ../data/images_all/ | Source direction of the images ready for being used for extract feature as gallery.}"
  67. "{caffemodellist | ../../testdata/cv/caffemodel_list.txt | caffe model for feature exrtaction.}"
  68. "{network_forIMG | ../../testdata/cv/3d_triplet_testIMG.prototxt | Network definition file used for extracting feature from a single image and making a classification}"
  69. "{mean_file | no | The mean file generated by Caffe from all gallery images, this could be used for mean value substraction from all images. If you want to use the mean file, you can set this as ../data/images_mean/triplet_mean.binaryproto.}"
  70. "{target_img1 | ../data/images_all/0_48.png | Path of image waiting to be classified.}"
  71. "{target_img2 | ../data/images_all/1_339.png | Path of image waiting to be classified.}"
  72. "{target_img3 | ../data/images_all/2_296.png | Path of image waiting to be classified.}"
  73. "{target_img4 | ../data/images_all/3_466.png | Path of image waiting to be classified.}"
  74. "{target_img5 | ../data/images_all/4_117.png | Path of image waiting to be classified.}"
  75. "{target_img6 | ../data/images_all/5_236.png | Path of image waiting to be classified.}"
  76. "{feature_blob | feat | Name of layer which will represent as the feature, in this network, ip1 or feat is well.}"
  77. "{num_candidate | 4 | Number of candidates in gallery as the prediction result.}"
  78. "{device | CPU | Device type: CPU or GPU}"
  79. "{dev_id | 0 | Device id}";
  80. /* get parameters from comand line */
  81. cv::CommandLineParser parser(argc, argv, keys);
  82. parser.about("Feature extraction and classification");
  83. if (parser.has("help"))
  84. {
  85. parser.printMessage();
  86. return 0;
  87. }
  88. String src_dir = parser.get<String>("src_dir");
  89. String caffemodellist = parser.get<String>("caffemodellist");
  90. String network_forIMG = parser.get<String>("network_forIMG");
  91. String mean_file = parser.get<String>("mean_file");
  92. String target_img1 = parser.get<String>("target_img1");
  93. String target_img2 = parser.get<String>("target_img2");
  94. String target_img3 = parser.get<String>("target_img3");
  95. String target_img4 = parser.get<String>("target_img4");
  96. String target_img5 = parser.get<String>("target_img5");
  97. String target_img6 = parser.get<String>("target_img6");
  98. String feature_blob = parser.get<String>("feature_blob");
  99. int num_candidate = parser.get<int>("num_candidate");
  100. String device = parser.get<String>("device");
  101. ifstream namelist_model(caffemodellist.c_str(), ios::in);
  102. vector<String> caffemodel;
  103. char *buf = new char[512];
  104. int number_model = 0;
  105. while (!namelist_model.eof())
  106. {
  107. namelist_model.getline(buf, 512);
  108. caffemodel.push_back(buf);
  109. number_model++;
  110. }
  111. /* List the file names under a given path */
  112. std::vector<String> name_gallery;
  113. listDir(src_dir.c_str(), name_gallery, false);
  114. for (unsigned int i = 0; i < name_gallery.size(); i++)
  115. {
  116. name_gallery[i] = src_dir + name_gallery[i];
  117. }
  118. std::vector<cv::Mat> img_gallery;
  119. cv::Mat temp_feat;
  120. vector<cv::Mat> feature_reference;
  121. vector<cv::Mat> feature_test1;
  122. vector<cv::Mat> feature_test2;
  123. vector<cv::Mat> feature_test3;
  124. vector<cv::Mat> feature_test4;
  125. vector<cv::Mat> feature_test5;
  126. vector<cv::Mat> feature_test6;
  127. cv::Mat img_test1 = cv::imread(target_img1, -1);
  128. cv::Mat img_test2 = cv::imread(target_img2, -1);
  129. cv::Mat img_test3 = cv::imread(target_img3, -1);
  130. cv::Mat img_test4 = cv::imread(target_img4, -1);
  131. cv::Mat img_test5 = cv::imread(target_img5, -1);
  132. cv::Mat img_test6 = cv::imread(target_img6, -1);
  133. for (int num_model = 0; num_model < number_model; ++num_model)
  134. {
  135. feature_reference.push_back(temp_feat);
  136. feature_test1.push_back(temp_feat);
  137. feature_test2.push_back(temp_feat);
  138. feature_test3.push_back(temp_feat);
  139. feature_test4.push_back(temp_feat);
  140. feature_test5.push_back(temp_feat);
  141. feature_test6.push_back(temp_feat);
  142. }
  143. for (unsigned int i = 0; i < name_gallery.size(); i++)
  144. {
  145. img_gallery.push_back(cv::imread(name_gallery[i], -1));
  146. }
  147. /* Initialize a net work with Device */
  148. cv::cnn_3dobj::descriptorExtractor descriptor(device);
  149. std::cout << "Using" << descriptor.getDeviceType() << std::endl;
  150. /* Load net with the caffe trained net work parameter and structure */
  151. for (int num_model = 0; num_model < number_model; ++num_model)
  152. {
  153. if (strcmp(mean_file.c_str(), "no") == 0)
  154. descriptor.loadNet(network_forIMG, caffemodel[num_model]);
  155. else
  156. descriptor.loadNet(network_forIMG, caffemodel[num_model], mean_file);
  157. /* Part1: Extract feature from a set of images and a single image*/
  158. descriptor.extract(img_gallery, feature_reference[num_model], feature_blob);
  159. descriptor.extract(img_test1, feature_test1[num_model], feature_blob);
  160. descriptor.extract(img_test2, feature_test2[num_model], feature_blob);
  161. descriptor.extract(img_test3, feature_test3[num_model], feature_blob);
  162. descriptor.extract(img_test4, feature_test4[num_model], feature_blob);
  163. descriptor.extract(img_test5, feature_test5[num_model], feature_blob);
  164. descriptor.extract(img_test6, feature_test6[num_model], feature_blob);
  165. }
  166. /* Initialize a matcher which using L2 distance. */
  167. cv::BFMatcher matcher(NORM_L2);
  168. vector<vector<vector<cv::DMatch> > > matches1;
  169. vector<vector<vector<cv::DMatch> > > matches2;
  170. vector<vector<vector<cv::DMatch> > > matches3;
  171. vector<vector<vector<cv::DMatch> > > matches4;
  172. vector<vector<vector<cv::DMatch> > > matches5;
  173. vector<vector<vector<cv::DMatch> > > matches6;
  174. vector<vector<cv::DMatch> > matches_temp;
  175. for (int num_model = 0; num_model < number_model; ++num_model)
  176. {
  177. matches1.push_back(matches_temp);
  178. matches2.push_back(matches_temp);
  179. matches3.push_back(matches_temp);
  180. matches4.push_back(matches_temp);
  181. matches5.push_back(matches_temp);
  182. matches6.push_back(matches_temp);
  183. }
  184. /* Have a KNN match on the target and reference images. */
  185. for (int num_model = 0; num_model < number_model; ++num_model)
  186. {
  187. matcher.knnMatch(feature_test1[num_model], feature_reference[num_model], matches1[num_model], num_candidate+1);
  188. matcher.knnMatch(feature_test2[num_model], feature_reference[num_model], matches2[num_model], num_candidate+1);
  189. matcher.knnMatch(feature_test3[num_model], feature_reference[num_model], matches3[num_model], num_candidate+1);
  190. matcher.knnMatch(feature_test4[num_model], feature_reference[num_model], matches4[num_model], num_candidate+1);
  191. matcher.knnMatch(feature_test5[num_model], feature_reference[num_model], matches5[num_model], num_candidate+1);
  192. matcher.knnMatch(feature_test6[num_model], feature_reference[num_model], matches6[num_model], num_candidate+1);
  193. }
  194. vector<Mat> img_merge;
  195. /* Part2: Start to have a show */
  196. viz::Viz3d myWindow0("Instruction");
  197. viz::Viz3d myWindow1("Point Cloud");
  198. viz::Viz3d myWindow2("Prediction sample");
  199. /* Set window size as 1024*1024, we use this scale as default. */
  200. myWindow0.setWindowSize(Size(1300,100));
  201. myWindow0.setWindowPosition(Point(0,800));
  202. myWindow1.setWindowSize(Size(700,600));
  203. myWindow1.setWindowPosition(Point(600,0));
  204. myWindow2.setWindowSize(Size(600,600));
  205. myWindow2.setWindowPosition(Point(-20,0));
  206. /* Pose of the widget in camera frame */
  207. Affine3f cloud_pose = Affine3f().translate(Vec3f(1.0f,1.0f,1.0f));
  208. Point3d campos(1,0,0);
  209. /* Get the transformation matrix from camera coordinate system to global. */
  210. Affine3f transform = viz::makeTransformToGlobal(Vec3f(1.0f,0.0f,0.0f), Vec3f(0.0f,1.0f,0.0f), Vec3f(0.0f,0.0f,1.0f), campos);
  211. /* Pose of the widget in global frame */
  212. Affine3f cloud_pose_global = transform * cloud_pose;
  213. /* Set background color. */
  214. myWindow0.setBackgroundColor(viz::Color::white());
  215. myWindow1.setBackgroundColor(viz::Color::white());
  216. myWindow2.setBackgroundColor(viz::Color::white());
  217. Point3d cam_y_dir(0.0f,0.0f,1.0f);
  218. cv::cnn_3dobj::icoSphere ViewSphere(1,0);
  219. Mat bunny_cloud;
  220. Point3d cam_focal_point;
  221. float radius;
  222. float translation_phase = 0.0;
  223. int count_pre, num_rotate, max_rotate;
  224. String titlename, Hint, Pred("prediction: ");
  225. vector<viz::WImageOverlay> imagepredict;
  226. String widgename[24] = {"1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24"};
  227. vector<Mat> slide;
  228. slide.push_back(imread("1.png"));
  229. slide.push_back(imread("2.png"));
  230. slide.push_back(imread("3.png"));
  231. slide.push_back(imread("4.png"));
  232. slide.push_back(imread("5.png"));
  233. slide.push_back(imread("6.png"));
  234. slide.push_back(imread("7.png"));
  235. slide.push_back(imread("8.png"));
  236. slide.push_back(imread("9.png"));
  237. slide.push_back(imread("10.png"));
  238. /// Create a window
  239. viz::Viz3d myWindowS("Slide Show");
  240. myWindowS.setWindowSize(Size(1300,700));
  241. myWindowS.setWindowPosition(Point(0,0));
  242. myWindowS.setBackgroundColor(viz::Color::white());
  243. for (size_t i = 0; i < slide.size(); ++i)
  244. {
  245. /// Create a triangle widget
  246. viz::WImageOverlay slide1(slide[i],Rect(0, 0, 1300, 700));
  247. /// Show widget in the visualizer window
  248. num_rotate = 0;
  249. if (i == 0)
  250. max_rotate = 2000;
  251. else
  252. max_rotate = 230;
  253. while (num_rotate != max_rotate)
  254. {
  255. myWindowS.showWidget("Slide1", slide1);
  256. /// Start event loop
  257. myWindowS.spinOnce(1, true);
  258. num_rotate++;
  259. }
  260. }
  261. for (int num_model = 0; num_model < number_model; ++num_model)
  262. {
  263. if (num_model == 0)
  264. Hint = "Start training.";
  265. else if (num_model == 28)
  266. Hint = "Different Classes Are Clustered.";
  267. else if(num_model == 40)
  268. Hint = "Poses Are Set apart.";
  269. else if(num_model == 42)
  270. Hint = "Finished. Model could: tell both classes and poses.";
  271. titlename = caffemodel[num_model];
  272. titlename = "Prediction Result of Model Trained on Iteration " + titlename.substr(34, titlename.length() - 44);
  273. viz::WText title(titlename, Point(100, 50), 30, viz::Color::black());
  274. viz::WText hint(Hint, Point(400, 20), 25, viz::Color::black());
  275. viz::WImageOverlay image3d1(img_test1, Rect(20, 40, img_test4.rows, img_test4.cols));
  276. viz::WText arrow1(Pred, Point(90,60), 15, viz::Color::red());
  277. viz::WImageOverlay image3d2(img_test2, Rect(20, 40+75, img_test4.rows, img_test4.cols));
  278. viz::WText arrow2(Pred, Point(90,60+75), 15, viz::Color::green());
  279. viz::WImageOverlay image3d3(img_test3, Rect(20, 40+75*2, img_test4.rows, img_test4.cols));
  280. viz::WText arrow3(Pred, Point(90,60+75*2), 15, viz::Color::purple());
  281. viz::WImageOverlay image3d4(img_test4, Rect(20, 40+75*3, img_test4.rows, img_test4.cols));
  282. viz::WText arrow4(Pred, Point(90,60+75*3), 15, viz::Color::blue());
  283. viz::WImageOverlay image3d5(img_test5, Rect(20, 40+75*4, img_test4.rows, img_test4.cols));
  284. viz::WText arrow5(Pred, Point(90,60+75*4), 15, viz::Color::yellow());
  285. viz::WImageOverlay image3d6(img_test6, Rect(20, 40+75*5, img_test4.rows, img_test4.cols));
  286. viz::WText arrow6(Pred, Point(90,60+75*5), 15, viz::Color::orange());
  287. viz::WText text_target(String("Query Image"), Point2d(20,530), 20, viz::Color::purple());
  288. viz::WText text_pred(String("Predicted Images using 4 NN"), Point2d(80+110,530), 20, viz::Color::purple());
  289. viz::WText text3d1(String("1st"), Point2d(80 + 110,500), 20, viz::Color::orange());
  290. viz::WText text3d2(String("2nd"), Point2d(80 + 2*110,500), 20, viz::Color::orange());
  291. viz::WText text3d3(String("3rd"), Point2d(80 + 3*110,500), 20, viz::Color::orange());
  292. viz::WText text3d4(String("4th"), Point2d(80 + 4*110,500), 20, viz::Color::orange());
  293. viz::WText classname1(String("ape: red"), Point2d(20,10), 11, viz::Color::red());
  294. viz::WText classname2(String("ant: green"), Point2d(120,10), 11, viz::Color::green());
  295. viz::WText classname3(String("cow: purple"), Point2d(220,10), 11, viz::Color::purple());
  296. viz::WText classname4(String("plane: blue"), Point2d(320,10), 11, viz::Color::blue());
  297. viz::WText classname5(String("bunny: yellow"), Point2d(420,10), 11, viz::Color::yellow());
  298. viz::WText classname6(String("horse: orange"), Point2d(500,10), 11, viz::Color::orange());
  299. myWindow0.showWidget("title", title, Affine3f().translate(Vec3f(0.0f,0.0f,0.0f)));
  300. myWindow0.showWidget("hint", hint, Affine3f().translate(Vec3f(0.0f,0.0f,0.0f)));
  301. myWindow2.showWidget("image3d1", image3d1, Affine3f().translate(Vec3f(1.0f,1.0f,1.0f)));
  302. myWindow2.showWidget("image3d2", image3d2, Affine3f().translate(Vec3f(1.0f,1.0f,1.0f)));
  303. myWindow2.showWidget("image3d3", image3d3, Affine3f().translate(Vec3f(1.0f,1.0f,1.0f)));
  304. myWindow2.showWidget("image3d4", image3d4, Affine3f().translate(Vec3f(1.0f,1.0f,1.0f)));
  305. myWindow2.showWidget("image3d5", image3d5, Affine3f().translate(Vec3f(1.0f,1.0f,1.0f)));
  306. myWindow2.showWidget("image3d6", image3d6, Affine3f().translate(Vec3f(1.0f,1.0f,1.0f)));
  307. myWindow2.showWidget("arrow1", arrow1, Affine3f().translate(Vec3f(1.0f,1.0f,1.0f)));
  308. myWindow2.showWidget("arrow2", arrow2, Affine3f().translate(Vec3f(1.0f,1.0f,1.0f)));
  309. myWindow2.showWidget("arrow3", arrow3, Affine3f().translate(Vec3f(1.0f,1.0f,1.0f)));
  310. myWindow2.showWidget("arrow4", arrow4, Affine3f().translate(Vec3f(1.0f,1.0f,1.0f)));
  311. myWindow2.showWidget("arrow5", arrow5, Affine3f().translate(Vec3f(1.0f,1.0f,1.0f)));
  312. myWindow2.showWidget("arrow6", arrow6, Affine3f().translate(Vec3f(1.0f,1.0f,1.0f)));
  313. myWindow2.showWidget("text_target", text_target, Affine3f().translate(Vec3f(0.0f,0.0f,0.0f)));
  314. myWindow2.showWidget("text_pred", text_pred, Affine3f().translate(Vec3f(0.0f,0.0f,0.0f)));
  315. myWindow2.showWidget("text3d1", text3d1, Affine3f().translate(Vec3f(0.0f,0.0f,0.0f)));
  316. myWindow2.showWidget("text3d2", text3d2, Affine3f().translate(Vec3f(0.0f,0.0f,0.0f)));
  317. myWindow2.showWidget("text3d3", text3d3, Affine3f().translate(Vec3f(0.0f,0.0f,0.0f)));
  318. myWindow2.showWidget("text3d4", text3d4, Affine3f().translate(Vec3f(0.0f,0.0f,0.0f)));
  319. myWindow2.showWidget("classname1", classname1, Affine3f().translate(Vec3f(0.0f,0.0f,0.0f)));
  320. myWindow2.showWidget("classname2", classname2, Affine3f().translate(Vec3f(0.0f,0.0f,0.0f)));
  321. myWindow2.showWidget("classname3", classname3, Affine3f().translate(Vec3f(0.0f,0.0f,0.0f)));
  322. myWindow2.showWidget("classname4", classname4, Affine3f().translate(Vec3f(0.0f,0.0f,0.0f)));
  323. myWindow2.showWidget("classname5", classname5, Affine3f().translate(Vec3f(0.0f,0.0f,0.0f)));
  324. myWindow2.showWidget("classname6", classname6, Affine3f().translate(Vec3f(0.0f,0.0f,0.0f)));
  325. bunny_cloud = cvcloud_load(feature_reference[num_model]);
  326. cam_focal_point = ViewSphere.getCenter(bunny_cloud);
  327. radius = ViewSphere.getRadius(bunny_cloud, cam_focal_point);
  328. viz::WCloud cloud_widget1(bunny_cloud.colRange(Range(0,641)), viz::Color::red());
  329. viz::WCloud cloud_widget2(bunny_cloud.colRange(Range(642,642*2-1)), viz::Color::green());
  330. viz::WCloud cloud_widget3(bunny_cloud.colRange(Range(642*2,642*3-1)), viz::Color::purple());
  331. viz::WCloud cloud_widget4(bunny_cloud.colRange(Range(642*3,642*4-1)), viz::Color::blue());
  332. viz::WCloud cloud_widget5(bunny_cloud.colRange(Range(642*4,642*5-1)), viz::Color::yellow());
  333. viz::WCloud cloud_widget6(bunny_cloud.colRange(Range(642*5,642*6-1)), viz::Color::orange());
  334. myWindow1.showWidget("obj1", cloud_widget1, cloud_pose_global);
  335. myWindow1.setRenderingProperty("obj1",0,3);
  336. myWindow1.showWidget("obj2", cloud_widget2, cloud_pose_global);
  337. myWindow1.setRenderingProperty("obj2",0,3);
  338. myWindow1.showWidget("obj3", cloud_widget3, cloud_pose_global);
  339. myWindow1.setRenderingProperty("obj3",0,3);
  340. myWindow1.showWidget("obj4", cloud_widget4, cloud_pose_global);
  341. myWindow1.setRenderingProperty("obj4",0,3);
  342. myWindow1.showWidget("obj5", cloud_widget5, cloud_pose_global);
  343. myWindow1.setRenderingProperty("obj5",0,3);
  344. myWindow1.showWidget("obj6", cloud_widget6, cloud_pose_global);
  345. myWindow1.setRenderingProperty("obj6",0,3);
  346. count_pre = 0;
  347. for (int j = 1; j < num_candidate+1; ++j)
  348. {
  349. myWindow2.showWidget(widgename[count_pre], viz::WImageOverlay(img_gallery[matches1[num_model][0][j].trainIdx], Rect(80+110*j, 40+75*0, img_test4.rows, img_test4.cols)), Affine3f().translate(Vec3f(1.0f,1.0f,1.0f)));
  350. count_pre++;
  351. myWindow2.showWidget(widgename[count_pre], viz::WImageOverlay(img_gallery[matches2[num_model][0][j].trainIdx], Rect(80+110*j, 40+75*1, img_test4.rows, img_test4.cols)), Affine3f().translate(Vec3f(1.0f,1.0f,1.0f)));
  352. count_pre++;
  353. myWindow2.showWidget(widgename[count_pre], viz::WImageOverlay(img_gallery[matches3[num_model][0][j].trainIdx], Rect(80+110*j, 40+75*2, img_test4.rows, img_test4.cols)), Affine3f().translate(Vec3f(1.0f,1.0f,1.0f)));
  354. count_pre++;
  355. myWindow2.showWidget(widgename[count_pre], viz::WImageOverlay(img_gallery[matches4[num_model][0][j].trainIdx], Rect(80+110*j, 40+75*3, img_test4.rows, img_test4.cols)), Affine3f().translate(Vec3f(1.0f,1.0f,1.0f)));
  356. count_pre++;
  357. myWindow2.showWidget(widgename[count_pre], viz::WImageOverlay(img_gallery[matches5[num_model][0][j].trainIdx], Rect(80+110*j, 40+75*4, img_test4.rows, img_test4.cols)), Affine3f().translate(Vec3f(1.0f,1.0f,1.0f)));
  358. count_pre++;
  359. myWindow2.showWidget(widgename[count_pre], viz::WImageOverlay(img_gallery[matches6[num_model][0][j].trainIdx], Rect(80+110*j, 40+75*5, img_test4.rows, img_test4.cols)), Affine3f().translate(Vec3f(1.0f,1.0f,1.0f)));
  360. count_pre++;
  361. }
  362. num_rotate = 0;
  363. max_rotate = 15;
  364. if (num_model == number_model-1)
  365. max_rotate = 30000;
  366. while (num_rotate != max_rotate)
  367. {
  368. translation_phase += CV_PI * 0.01f;
  369. campos.x = sin(translation_phase);
  370. campos.y = cos(translation_phase);
  371. campos.z = 0;
  372. /* Get the pose of the camera using makeCameraPoses. */
  373. Affine3f cam_pose = viz::makeCameraPose(campos*radius*3.5+cam_focal_point, cam_focal_point, cam_y_dir*radius*3.5+cam_focal_point);
  374. myWindow1.setViewerPose(cam_pose);
  375. myWindow1.spinOnce(1, true);
  376. myWindow2.spinOnce(1, true);
  377. myWindow0.spinOnce(1, true);
  378. num_rotate++;
  379. }
  380. myWindow0.removeAllWidgets();
  381. myWindow1.removeAllWidgets();
  382. myWindow2.removeAllWidgets();
  383. }
  384. return 0;
  385. }