我需要这样的东西,因为在我看来,当我这样做的时候
cvRectangle( CVframe, UL, LR, CV_RGB(0,256,53), CV_FILLED);
string cvtext;
cvtext += timeStr;
cvPutText(CVframe, cvtext.c_str(), cvPoint(0,(h/2+10)), &font , CV_RGB(0,0,0));
每次每秒24次cvRectangle不覆盖旧文本...
最佳答案
没有内置的 cvDeleteText
或类似的东西,这可能是有充分理由的。每当您在图像上放置文本时,它都会覆盖该图像中的像素,就像您将它们的值分别设置为 CV_RGB(0,0,0)
一样。如果您想撤消该操作,则需要存储之前存在的所有内容。由于不是每个人都想这样做,如果 cvPutText
自动跟踪它写入的像素,那将是浪费空间和时间。
最好的方法可能是有两个框架,其中一个永远不会被文本触及。代码看起来像这样。
//Initializing, before your loop that executes 24 times per second:
CvArr *CVframe, *CVframeWithText; // make sure they're the same size and format
while (looping) {
cvRectangle( CVframe, UL, LR, CV_RGB(0,256,53), CV_FILLED);
// And anything else non-text-related, do it to CVframe.
// Now we want to copy the frame without text.
cvCopy(CVframe, CVframeWithText);
string cvtext;
cvtext += timeStr;
// And now, notice in the following line that
// we're not overwriting any pixels in CVframe
cvPutText(CVframeWithText, cvtext.c_str(), cvPoint(0,(h/2+10)), &font , CV_RGB(0,0,0));
// And then display CVframeWithText.
// Now, the contents of CVframe are the same as if we'd "deleted" the text;
// in fact, we never wrote text to CVframe in the first place.
希望这对您有所帮助!
关于c++ - OpenCV - 是否有删除文本之类的东西?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4338411/