4 : modelfile (modelfile)
14 void CalibModel::onMouseStatic(
int event,
int x,
int y,
int flags,
void* param)
16 ((
CalibModel *)param)->onMouse(event,x,y,flags);
19 void CalibModel::onMouse(
int event,
int x,
int y,
int flags)
21 if (event == CV_EVENT_LBUTTONDOWN) {
24 for (
int i=0; i<4; i++) {
27 if (sqrt(
double(dx*dx+dy*dy)) <10) {
39 if (event == CV_EVENT_LBUTTONUP) {
76 image = cvLoadImage(modelfile, cvQueryFrame(capture)->nChannels == 3);
79 if (!interactiveSetup(capture))
return false;
86 if (!cvSaveImage(modelfile,
image))
return false;
89 string roifn = string(modelfile) +
".roi";
90 ofstream roif(roifn.c_str());
91 if (!roif.good())
return false;
92 for (
int i=0;i<4; i++)
101 for (
int i=0; i<4; i++) {
110 static void putText(IplImage *im,
const char *text, CvPoint p, CvFont *f1, CvFont *f2)
112 cvPutText(im,text,p,f2, cvScalarAll(0));
113 cvPutText(im,text,p,f1, cvScalar(0,255, 255));
117 bool CalibModel::interactiveSetup(CvCapture *capture)
120 CvFont font, fontbold;
122 cvInitFont( &font, CV_FONT_HERSHEY_PLAIN, 1, 1);
123 cvInitFont( &fontbold, CV_FONT_HERSHEY_PLAIN, 1, 1, 0, 5);
125 cvNamedWindow(win, CV_WINDOW_AUTOSIZE);
127 cvSetMouseCallback(win, onMouseStatic,
this);
131 IplImage *shot=0, *text=0;
135 bool accepted =
false;
139 char k = cvWaitKey(10);
141 if (k==27 || k==
'q') {
142 if (shot) cvReleaseImage(&shot);
143 if (text) cvReleaseImage(&text);
148 if (!pause || shot==0) {
149 frame = cvQueryFrame(capture);
151 text=cvCreateImage(cvGetSize(frame), IPL_DEPTH_8U, 3);
158 corners[2].y = frame->height-d;
160 corners[3].y = frame->height-d;
162 if (frame->nChannels==1)
163 cvCvtColor(frame, text, CV_GRAY2BGR);
167 if (shot->nChannels==1)
168 cvCvtColor(shot, text, CV_GRAY2BGR);
178 if (shot) cvCopy(frame,shot);
179 else shot = cvCloneImage(frame);
184 putText(text,
"Please take a frontal view",
cvPoint(3,20), &font, &fontbold);
185 putText(text,
"of a textured planar surface",
cvPoint(3,40), &font, &fontbold);
190 putText(text,
"Drag corners to match the",
cvPoint(3,20), &font, &fontbold);
191 putText(text,
"calibration target",
cvPoint(3,40), &font, &fontbold);
192 putText(text,
"press 'r' to restart",
cvPoint(3,60), &font, &fontbold);
193 putText(text,
"press space when ready",
cvPoint(3,80), &font, &fontbold);
203 cvPolyLine(text, &ptr, &four, 1, 1,
207 cvShowImage(win, text);
210 cvReleaseImage(&text);