如何在opencv檢測循環後執行一些shell腳本(例如1.sh)?如何在opencv檢測循環後執行一些shell腳本
我已經使用exec,它的工作原理,但opencv程序關閉後檢測到的圓圈,我想要的是該程序沒有關閉,直到我按下「q」鍵。
這裏是我的代碼:
#include<cv.h>
#include<highgui.h>
#include <math.h>
#include <stdlib.h>
#include <unistd.h>
using namespace std;
int main(int argc, char **argv)
{
CvCapture *capture = 0;
IplImage *img = 0;
int key = 0;
CvFont font;
cvInitFont(&font, CV_FONT_HERSHEY_PLAIN,1.0,1.0,0,1,CV_AA);
capture = cvCaptureFromCAM(0);
if (!capture) {
fprintf(stderr, "Cannot open initialize webcam!\n");
return 1;
}
cvNamedWindow("result", CV_WINDOW_AUTOSIZE);
img = cvQueryFrame(capture);
if (!img)
exit(1);
IplImage* gray = cvCreateImage(cvGetSize(img), 8, 1);
CvMemStorage* storage = cvCreateMemStorage(0);
while(key != 'q') {
img = cvQueryFrame(capture);
if(!img) break;
cvCvtColor(img, gray, CV_BGR2GRAY);
cvSmooth(gray, gray, CV_GAUSSIAN, 5, 5);
CvSeq* circles = cvHoughCircles(gray, storage, CV_HOUGH_GRADIENT, 2, >gray->height/40, 200, 100/*, 20, 100*/);
int i;
for(i = 0; i < circles->total; i++)
{
float* p = (float*)cvGetSeqElem(circles, i);
cvCircle(img, cvPoint(cvRound(p[0]),cvRound(p[1])), cvRound(p[2]), >CV_RGB(50,255,30), 5, 8, 0);
cvPutText(img, "CIRCLE",cvPoint(cvRound(p[0]+45),cvRound(p[1]+45)), &font, >CV_RGB(50,10,255));
if (circles) {
execl("./1.sh", (char *)0);
}
}
cvShowImage("result", img);
cvShowImage("gray", gray);
key = cvWaitKey(1);
}
// cvReleaseMemStorage(storage);
// cvReleaseImage(gray);
cvDestroyAllWindows();
cvDestroyWindow("result");
cvReleaseCapture(&capture);
return 0;
}
我使用Ubuntu的代碼塊。
這個問題,在這裏問,它已被刪除。 – ArtemStorozhuk 2012-07-21 09:26:28