gpt4 book ai didi

OpenCV,非特定文本

转载 作者:太空宇宙 更新时间:2023-11-03 21:47:52 25 4
gpt4 key购买 nike

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;
}}

最佳答案

cvPutText()exactly what you are looking for .

我的第一个技巧是一点优化:将以下代码放在 while 循环之前。由于您只需要一种字体类型,因此无需在每次循环迭代时都重新创建它。

CvFont font;
cvInitFont(&font, CV_FONT_HERSHEY_SIMPLEX, 1.0, 1.0, 0, 1, CV_AA);

现在回到您需要了解的内容:cvPutText() 的第二个参数是 const char* 类型。因此,您需要做的就是在循环的每次迭代中传递一个具有不同文本的变量。

下面的示例从捕获界面检索帧并将帧编号写入屏幕上显示的每个图像:

while (key != 27)
{
img = cvQueryFrame(capture);
if (!img)
{
fprintf(stderr, "!!! Failed to retrive frame!\n" );
break;
}

// convert int to char*
char msg[4*1024] = { 0 };
sprintf(msg, "Frame number: %d", frame_num);

cvPutText (img, msg, cvPoint(50,200), &font, cvScalar(255,255,0));
frame_num++;

cvShowImage("result", img);
key = cvWaitKey(33);
}

关于OpenCV,非特定文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12875780/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com