首先,我有这张图片,并希望制作一个可以检测出类似图片并从中删除圆圈(水印)的应用程序。
int main(){
Mat im1,im2,im3,gray,gray2,result;
im2=imread(" (2).jpg");
namedWindow("x",CV_WINDOW_FREERATIO);
imshow("x",im2);
//converting it to gray
cvtColor(im2,gray,CV_BGR2GRAY);
// creating a new image that will have the cropped ellipse
Mat ElipseImg(im2.rows,im2.cols,CV_8UC1,Scalar(0,0,0));
//detecting the largest circle
GaussianBlur(gray,gray,Size(5,5),0);
vector<Vec3f> circles;
HoughCircles(gray,circles,CV_HOUGH_GRADIENT,1,gray.rows/8,100,100,100,0);
uchar x;
int measure=0;int id=0;
for(int i=0;i<circles.size();i++){
if(cvRound(circles[i][2])>measure && cvRound(circles[i][2])<1000){
measure=cvRound(circles[i][2]);
id=i;
}
}
Point center(cvRound(circles[id][0]),cvRound(circles[id][1]));
int radius=cvRound(circles[id][2]);
circle(im2,center,3,Scalar(0,255,0),-1,8,0);
circle(im2,center,radius,Scalar(0,255,0),2,8,0);
ellipse(ElipseImg,center,Size(radius,radius),0,0,360,Scalar(255,255,255),-1,8);
cout<<"center: "<<center<<" radius: "<<radius<<endl;
Mat res;
bitwise_and(gray,ElipseImg,result);
namedWindow("bitwise and",CV_WINDOW_FREERATIO);
imshow("bitwise and",result);
// trying to estimate the Intensity of the circle for the thresholding
x=result.at<uchar>(cvRound(circles[id][0]+30),cvRound(circles[id][1]));
cout<<(int)x;
//thresholding the output image
threshold(ElipseImg,ElipseImg,(int)x-10,250,CV_THRESH_BINARY);
namedWindow("threshold",CV_WINDOW_FREERATIO);
imshow("threshold",ElipseImg);
// making bitwise_or
bitwise_or(gray,ElipseImg,res);
namedWindow("bitwise or",CV_WINDOW_FREERATIO);
imshow("bitwise or",res);
waitKey(0);
}
到目前为止,我所做的是:
- 将其转换为灰度
- 使用霍夫圆变换检测最大的圆并在一个新图像中制作相同半径的圆
- 使用 (
bitwise_and
) 将这个新圆和灰度图像进行与运算,得到只有这个圆的图像 - 对这个新图像进行二值化处理
- 将阈值的结果与原图像进行 (
bitwise_or
) 运算
我的问题是,在这个圆内部弯曲的白线上的任何黑色文本都没有出现。我尝试使用像素值而不是阈值来消除颜色,但问题仍然存在。是否有解决方案或建议?