opencv字符叠加

主要参考文献:

 参考1

 参考2

参考3

参考4

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

仅为自己平时工作学习的笔记。。欢迎指正。

 

发布了236 篇原创文章 · 获赞 82 · 访问量 140万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章