主要參考文獻:
putText() 函數是不支持\n換行的。。 所以要自己去換行。
CvScalar font_size;
Text.getFont(NULL, &font_size, NULL, NULL);
std::string str(astr); // astr爲被疊加的字符串,以\n爲換行標誌
std::string::size_type pos_begain = 0;
std::string::size_type pos_end = pos_begain;
int i = 0;
//逐行疊加
while( (pos_end = str.find('\n', pos_begain)) != std::string::npos )
{
std::string str_tmp = str.substr(pos_begain, pos_end - pos_begain);
std::cout << str_tmp << std::endl;
pos_begain = pos_end + 1;
Text.putText(img, str_tmp.c_str() , cvPoint(80, 200 + i * font_size.val[0]), cvScalar(255, 0, 0));
i++;
}
//最後一行疊加字符
std::string str_tmp = str.substr(pos_begain);
Text.putText(img, str_tmp.c_str() , cvPoint(80, 200 + i * font_size.val[0]), m_cvColor);
僅爲自己平時工作學習的筆記。。歡迎指正。