【发布时间】:2016-10-17 16:14:59
【问题描述】:
我有一个项目来跟踪在 java 中使用 opencv 的玩具车,但我不知道如何检测并为后面的汽车创建一个矩形。以下是我所有的想法和方法,但它仍然没有检测到好。
我的目标是检测车后。像这样的东西(我用Paint来画:))
我的想法是:
_将 rgb 图像转换为灰度图像。使用 Canny 检测寻找边缘,使用 GaussianBlur 使图像更平滑
Imgproc.cvtColor(mImageRGBA, thresholded, Imgproc.COLOR_RGB2GRAY,3);
Imgproc.Canny(thresholded, thresholded, 78, 212);
Imgproc.GaussianBlur(thresholded, thresholded, new Size(5, 5), 2.2, 2);
我的图片会是这样的
_然后,我将使用 findcontour 找到汽车的轮廓并绘制它。
List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
Mat mHierarchy = new Mat();
Imgproc.findContours(thresholded, contours, mHierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);
for( int i = 0; i< contours.size(); i++ ) {
circle_contour = contours.get(i).toArray();
double contour_length = circle_contour.length;
if (contour_length < 50) continue;
Imgproc.drawContours(thresholded,contours,i,new Scalar(255,255,255),2);
.
.
.
最后,我不会绘制轮廓,我使用 minAreaRec 来查找大小合适的矩形。我要这个矩形。
//Imgproc.drawContours(thresholded,contours,i,new Scalar(255,255,255),2);// remove this line and continue to find rectangle for car.
.
.
.
Car_Rect = Imgproc.minAreaRect(new MatOfPoint2f(contours.get(i).toArray()));
float rect_width = Car_Rect.boundingRect().width;
float rect_height = Car_Rect.boundingRect().height;
float rect_ratio = rect_width/rect_height;
Point points[] = new Point[4];
Car_Rect.points(points);
if((Car_Rect.angle<=value1)&&(rect_width>value7)&&(rect_width<value8)&&(rect_height>value9)&&(rect_height<value10))
{
Imgproc.line(thresholded,points[0],points[1],new Scalar(255, 255, 255),2);
Imgproc.line(thresholded,points[1],points[2],new Scalar(255,255,255),2);
Imgproc.line(thresholded,points[2],points[3],new Scalar(255,255,255),2);
Imgproc.line(thresholded,points[3],points[0],new Scalar(255,255,255),2);
}
value1, value7, value8, value9, value10 是角度、最小高度、最大高度、最小宽度、最大宽度的值,我限制汽车矩形的大小。我使用轨迹栏来调整它。 虽然我尝试调整 value1、7、8、9、10 是最好的,但结果并不好。它仍然有一些噪音:(
所以现在,我想问的问题是,这是检测玩具车后面的正确方法吗???,如果不是,是否有其他方法可以做到这一点。还是我错过了什么,某个步骤???我怎样才能准确地检测汽车后面的高度,矩形的宽度最稳定???
感谢您的每一个回答,非常感谢您
【问题讨论】:
标签: java android c++ opencv image-processing