int t = 0;
//char u;
// Loop controling vars
char keypress;
bool quit = false;
while (quit == false)
{ pFrame = cvQueryFrame(pCapture);//
cvLine(pFrame, /* the dest image */
cvPoint(0, 240), /* start point */
cvPoint(640, 240), /* end point */
cvScalar(0, 255, 0, 0), /* the color; green */
1, 8, 0); /* thickness, line type, shift */
CvMemStorage* storage = cvCreateMemStorage(0);
cvCvtColor(pFrame, tempFrame, CV_BGR2GRAY);
pProcessedFrame = findEdges(pFrame, lowSliderPosition, highSliderPosition, 3);//Επεξεργάσου για να βρεις τις άκρες
cvSmooth(tempFrame, tempFrame, CV_GAUSSIAN, 11, 11);//Για να αποφευχθούν λάθος εμφανίσεις κύκλου.
CvSeq* circles = cvHoughCircles(tempFrame, storage, CV_HOUGH_GRADIENT, 1, tempFrame->height/4, 50, 50, 20, 75);
for (size_t i = 0; i < circles->total; i++)
{
// round the floats to an int
float* p = (float*)cvGetSeqElem(circles, i);
cv::Point center(cvRound(p[0]), cvRound(p[1]));
int radius = cvRound(p[2]);
cvCircle(pFrame, center, 3, CV_RGB(0,255,0), -1, 8, 0 );//Ζωγράφισε το κέντρο του κύκλου.
cvCircle(pFrame, center, radius+1, CV_RGB(0,0,255), 2, 8, 0 );//Ζωγράφισε το περίγραμμα του κύκλου.
if (center.y == 240 )
{cvWaitKey(150);
t++;
}
else
{}
printf("x: %d y: %d r: %d t: %d\n",center.x,center.y, radius,t);
}
CvFont font;
cvInitFont(&font, CV_FONT_HERSHEY_SIMPLEX, 1.0, 1.0, 0, 1, CV_AA);
cvPutText(pProcessedFrame, "blabla", cvPoint(10, 130), &font, cvScalar(255, 255, 255, 0));
cvShowImage("WebCam", pFrame);//Εμφάνισε τα κανονικά frame στο παράθυρο αυτό
cvShowImage("Processed WebCam", pProcessedFrame);//Δείξε τα επεξεργασμένα frame στο παράθυρο αυτό.
keypress = cvWaitKey(20);//Περίμενε 20 msec.
if (keypress == 27)//Άλλαξε το flag σε quit αν πατηθεί το πλήκτρο escape.
{
quit = true;
}} //Τέλος του while
大家好,我相信这个问题并不难,但由于某种原因,我似乎无法在互联网上找到任何答案。也许我没有做一些好的研究。
我的程序上有一个名为 t 的计数器(整数)。根据我正在做的一些相机交互,它会不时变化。我只想将其显示在视频结果中,即名为 pProcessedFrame 的视频结果中。
我在这里包含的命令 cvPutText 对我不起作用,因为它只能显示特定的文本。我希望它像我之前提到的那样不时改变。
还有其他我不知道的命令吗?
@@编辑@@
好的,伙计们,这在下面得到了回答。我只是把最后的while代码和声明放在里面。也许有一天有人会需要这个。非常感谢大家。xD
int t = 0;
char u=0;
// Loop controling vars
char keypress;
bool quit = false;
char msg[4*1024] = { 0 };
int frame_num = 0;
while (quit == false)
{
pFrame = cvQueryFrame(pCapture);
cvLine(pFrame,
cvPoint(0, 240),
cvPoint(640, 240),
cvScalar(0, 255, 0, 0), 1, 8, 0);
CvMemStorage* storage = cvCreateMemStorage(0);
cvCvtColor(pFrame, tempFrame, CV_BGR2GRAY);
pProcessedFrame = findEdges(pFrame, lowSliderPosition, highSliderPosition, 3);
cvSmooth(tempFrame, tempFrame, CV_GAUSSIAN, 11, 11);
CvSeq* circles = cvHoughCircles(tempFrame, storage, CV_HOUGH_GRADIENT, 1, tempFrame->height/4, 50, 50, 20, 60);
for (size_t i = 0; i < circles->total; i++)
{
// round the floats to an int
float* p = (float*)cvGetSeqElem(circles, i);
cv::Point center(cvRound(p[0]), cvRound(p[1]));
int radius = cvRound(p[2]);
cvCircle(pFrame, center, 3, CV_RGB(0,255,0), -1, 8, 0 );
cvCircle(pFrame, center, radius+1, CV_RGB(0,0,255), 2, 8, 0 );
if (center.y == 240 )
{
cvWaitKey(200);
t++;
frame_num=t;
}
else
{}
printf("x: %d y: %d r: %d t: %d\n",center.x,center.y, radius,t);
}
sprintf(msg, "Counter: %d", frame_num);
cvPutText (pFrame, msg, cvPoint(50,100), &font, cvScalar(255,255,0));
cvShowImage("WebCam", pFrame);
cvShowImage("Processed WebCam", pProcessedFrame);
keypress = cvWaitKey(20);
if (keypress == 27)
{
quit = true;
}}