【发布时间】:2016-03-09 20:37:14
【问题描述】:
我是 JavaCv 的新手。我的任务是在图像上找到符号并生成带有单个符号的图片。 首先,我有这张图: 然后我做阈值并得到这个: 我正在尝试使用 cvFindContours 然后在每个符号周围画一个矩形,我的代码:
String filename = "captcha.jpg";
IplImage firstImage=cvLoadImage(filename);
Mat src = imread(filename, CV_LOAD_IMAGE_GRAYSCALE);
Mat dst = new Mat();
threshold(src, dst, 200, 255, 0);
imwrite("out.jpg", dst);
IplImage iplImage=cvLoadImage("out.jpg",CV_8UC1);
CvMemStorage memStorage=CvMemStorage.create();
CvSeq contours=new CvSeq();
cvFindContours(iplImage,memStorage,contours,Loader.sizeof(CvContour.class),CV_RETR_CCOMP,CV_CHAIN_APPROX_SIMPLE,cvPoint(0,0));
CvSeq ptr;
CvRect bb;
for (ptr=contours;ptr!=null;ptr=ptr.h_next()){
bb=cvBoundingRect(ptr);
cvRectangle(firstImage , cvPoint( bb.x(), bb.y() ),
cvPoint( bb.x() + bb.width(), bb.y() + bb.height()),
CvScalar.BLACK, 2, 0, 0 );
}
cvSaveImage("result.jpg",firstImage);
}
请,需要你的帮助。
【问题讨论】:
-
为什么不使用 OpenCV 2.x 或 3.0 功能?在我看来,这些 cv~~ 功能最近几乎被弃用了。
标签: java opencv captcha javacv