c++ - OpenCV - 是否有删除文本之类的东西?

标签 c++ c opencv

我需要这样的东西,因为在我看来,当我这样做的时候

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/

相关文章:

c++ - C++错误:多维数组的初始化程序太多

比较两种不同类型的指针

c - 什么可能导致死循环,由 linux 内核中的 print "Dead loop on virtual device "指示?

C++ 类内部结构在其方法中动态分配

c++ - 无法在编辑控件上设置字体

python - 二值化后创建可读的单词

python - 如何使用 numpy 为图像的所有相对白色部分创建蒙版?

opencv - 如何通过OpenCV用序列图像制作视频

c++ - 引用元组初始化引用元组

创建线程