这些问题是对这个问题的后续,我有一张我想从中删除徽标的图像,我已经侵蚀了图像,直到所有小文本都消失了,只剩下徽标,现在我有两张图像,原始图像和仅带有徽标的图像,现在当我尝试减去这两个图像以形成第三个仅包含文本的图像时,发生了奇怪的事情,徽标没有被删除,但已被概述
代码:
cv::Mat final;
cv::Mat greyMat = [self.imageView.image CVGrayscaleMat];
cv::Mat bwMat,erodedMat;
cv::threshold(greyMat, bwMat, 128, 255, CV_THRESH_BINARY);
cv::bitwise_not(bwMat, bwMat);
cv::Mat element = cv::getStructuringElement(cv::MORPH_RECT, cv::Size(20, 12));
cv::erode(bwMat, erodedMat, element);
cv::dilate(bwMat, erodedMat, bwMat);//I used this to restore all the missed components of the logo during erosion,bwMat in the last argument acts as a mask, i didn't sure of this
std::vector<cv::Point>points;
cv::Mat_<uchar>::iterator it=bwMat.begin<uchar>();
cv::Mat_<uchar>::iterator end=bwMat.end<uchar>();
for (; it!=end; ++it)
if (*it)
points.push_back(it.pos());
final=bwMat-erodedMat;