4 : modelfile (modelfile)
16 void CalibModel::onMouse(
int event,
int x,
int y,
int flags)
18 if (event == CV_EVENT_LBUTTONDOWN) {
21 for (
int i=0; i<4; i++) {
24 if (sqrt((
double)(dx*dx+dy*dy)) <10) {
36 if (event == CV_EVENT_LBUTTONUP) {
74 image = cvLoadImage(modelfile, cvQueryFrame(capture)->nChannels == 3);
77 if (!interactiveSetup(capture))
return false;
80 if (!detector.
build(
image, 400, 32, 3, 16, 3,0, 0))
84 if (!cvSaveImage(modelfile,
image))
return false;
87 string roifn = string(modelfile) +
".roi";
88 ofstream roif(roifn.c_str());
89 if (!roif.good())
return false;
90 for (
int i=0;i<4; i++)
95 detector.
save(
string(modelfile)+
".classifier");
99 for (
int i=0; i<4; i++) {
108 static void putText(IplImage *im,
const char *text, CvPoint p, CvFont *f1, CvFont *f2)
110 cvPutText(im,text,p,f2, cvScalarAll(0));
111 cvPutText(im,text,p,f1, cvScalar(0,255, 255));
117 static IplImage *s=0;
118 IplImage *frame =cvRetrieveFrame(capture);
119 if (frame == 0)
return 0;
121 if (frame->nChannels==1) {
122 if (!s) s=cvCreateImage(cvSize(frame->width,frame->height), IPL_DEPTH_8U, 3);
123 cvCvtColor(frame,s,CV_GRAY2BGR);
127 if (!s) s=cvCreateImage(cvSize(frame->width,frame->height), IPL_DEPTH_8U, 3);
136 cvGrabFrame(capture);
142 bool CalibModel::interactiveSetup(CvCapture *capture)
145 CvFont font, fontbold;
147 cvInitFont( &font, CV_FONT_HERSHEY_PLAIN, 1, 1);
148 cvInitFont( &fontbold, CV_FONT_HERSHEY_PLAIN, 1, 1, 0, 5);
150 cvNamedWindow(win, CV_WINDOW_AUTOSIZE);
154 cvSetMouseCallback(win, onMouseStatic,
this);
158 IplImage *shot=0, *text=0;
162 bool accepted =
false;
166 char k = cvWaitKey(10);
168 if (k==27 || k==
'q') {
169 if (shot) cvReleaseImage(&shot);
170 if (text) cvReleaseImage(&text);
175 if (!pause || shot==0) {
178 text=cvCreateImage(cvGetSize(frame), IPL_DEPTH_8U, 3);
185 corners[2].y = frame->height-d;
187 corners[3].y = frame->height-d;
189 if (frame->nChannels==1)
190 cvCvtColor(frame, text, CV_GRAY2BGR);
194 if (shot->nChannels==1)
195 cvCvtColor(shot, text, CV_GRAY2BGR);
205 if (shot) cvCopy(frame,shot);
206 else shot = cvCloneImage(frame);
211 putText(text,
"Please take a frontal view",
cvPoint(3,20), &font, &fontbold);
212 putText(text,
"of a textured planar surface",
cvPoint(3,40), &font, &fontbold);
217 putText(text,
"Drag corners to match the",
cvPoint(3,20), &font, &fontbold);
218 putText(text,
"calibration target",
cvPoint(3,40), &font, &fontbold);
219 putText(text,
"press 'r' to restart",
cvPoint(3,60), &font, &fontbold);
220 putText(text,
"press space when ready",
cvPoint(3,80), &font, &fontbold);
230 cvPolyLine(text, &ptr, &four, 1, 1,
234 cvShowImage(win, text);
237 cvReleaseImage(&text);
242 void CalibModel::onMouseStatic(
int event,
int x,
int y,
int flags,
void* param)
245 ((
CalibModel *)param)->onMouse(event,x,y,flags);
247 objectPtr->onMouse(event,x,y,flags);
249 cerr <<
"onMouseStatic(): null-pointer.\n";