Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #include "opencv/cv.h"
00044 #include "opencv/highgui.h"
00045 #include <iostream>
00046 #include <vector>
00047 #include <string>
00048 #include "ccd/sift_init.h"
00049 #include "ccd/bspline.h"
00050 #include <fstream>
00051 using namespace std;
00052 using namespace cv;
00053 vector<cv::Point3d> pts;
00054 void on_mouse(int event, int x, int y, int flags, void* param )
00055 {
00056
00057
00058 cv::Mat *image = (cv::Mat *)param;
00059 if( image->empty())
00060 return;
00061
00062
00063
00064
00065
00066 switch( event )
00067 {
00068 case CV_EVENT_LBUTTONDOWN:
00069 break;
00070 case CV_EVENT_LBUTTONUP:
00071 cv::circle(*image,cv::Point(x,y),2,cv::Scalar(0,0,255),2);
00072 pts.push_back(cv::Point3d(x,y,1.0));
00073 cv::imshow("Contour", *image);
00074 break;
00075 }
00076 }
00077
00078 int main (int argc, char * argv[])
00079 {
00080 char key;
00081 cv::Mat tpl = cv::imread(argv[1]);
00082 cv::namedWindow("Contour", 1);
00083 cv::setMouseCallback( "Contour", on_mouse, (void*)&tpl);
00084 cv::imshow("Contour", tpl);
00085 while (1)
00086 {
00087 key = cv::waitKey(10);
00088 if (key == 27) break;
00089 }
00090 cv::Mat contour_mat(pts.size(),3,CV_64FC1);
00091 for (size_t i = 0; i < pts.size(); ++i){
00092 double *ptr = contour_mat.ptr<double>(i);
00093 ptr[0] = pts[i].x;
00094 ptr[1] = pts[i].y;
00095 ptr[2] = pts[i].z;
00096 }
00097
00098 FileStorage fs("contour.xml", cv::FileStorage::WRITE);
00099 fs.open("contour.xml", FileStorage::WRITE);
00100 fs<< "contour_points" << contour_mat ;
00101 fs.release();
00102
00103
00104 CvFileStorage* new_fs= cvOpenFileStorage("contour.xml", 0, CV_STORAGE_READ);
00105 CvMat *coordinates= (CvMat*)cvReadByName(new_fs, NULL, "contour_points", NULL);
00106
00107 int step = coordinates->step/sizeof(double);
00108 double *ptr = coordinates->data.db;
00109 vector<cv::Point3d> test(pts.size());
00110 for (int i = 0; i < coordinates->rows; ++i)
00111 {
00112 test[i].x = (ptr+i*step)[0];
00113 test[i].y = (ptr+i*step)[1];
00114 test[i].z = (ptr+i*step)[2];
00115 std::cout << test[i].x << " " << test[i].y << " " <<test[i].z<< std::endl;
00116 }
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132 return 0;
00133 }