2010-12-02 76 views
1

我需要這樣的東西,因爲在我看來,當我每次做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)); 

每秒cvRectangle 24次不覆蓋舊的文本......

回答

6

有沒有內置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. 

希望這有助於!