【发布时间】:2012-08-19 20:02:54
【问题描述】:
目前我正在开发图像处理项目,我正在使用 javacv 开发图像处理组件。我能够提取图像的一些有趣部分,现在我需要读取这些对象的 x 和 y 坐标。 这是我提取的图像
我需要识别这些对象并在这些对象周围绘制正方形。我浏览了一些教程并尝试使用以下代码识别对象。
IplImage img="sourceimage";
CvSize sz = cvSize(img.width(), img.height());
IplImage gry=cvCreateImage(sz, img.depth(), 1);
cvCvtColor(img, gry, CV_BGR2GRAY);
cvThreshold(gry, gry, 200, 250, CV_THRESH_BINARY);
CvMemStorage mem = CvMemStorage.create();
CvSeq contours = new CvSeq();
CvSeq ptr = new CvSeq();
cvFindContours(gry, mem, contours, Loader.sizeof(CvContour.class) , CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0));
CvRect boundbox;
for (ptr = contours; ptr != null; ptr = ptr.h_next()) {
boundbox = cvBoundingRect(ptr, 0);
if(boundbox.height()>10||boundbox.height()>10){
cvRectangle( gry, cvPoint( boundbox.x(), boundbox.y() ), cvPoint( boundbox.x() + boundbox.width(), boundbox.y() + boundbox.height()),CvScalar.BLUE, 0, 0, 0 );
System.out.println(boundbox.x()+", "+boundbox.y());
}
}
cvShowImage("contures", gry);
cvWaitKey(0);
但它不会在对象周围绘制为矩形。我想知道我是否可以使用 cvFindContours 方法来识别这些对象?请有人解释一下如何使用 javacv/opencv 归档我的目标?
【问题讨论】:
-
那么当您绘制这些矩形时,它们与您拥有的对象的关系如何?
-
为什么忽略你的问题的答案??
-
@MahdeTo 我需要知道如何在这些对象周围绘制矩形。
-
@Astor 我没有忽略这些答案我正在检查这些答案,因为我必须将它们转换为 javacv。但是 thnax 4 rply。
标签: java opencv image-processing javacv