【发布时间】:2015-12-24 03:58:00
【问题描述】:
我在使用适用于 Android 的 opencv 2.4 检测速度交通标志时遇到问题。 我执行以下操作:
“捕获帧 -> 将其转换为 HSV -> 提取红色区域 -> 使用椭圆检测检测标志”
到目前为止,只要图片质量好,椭圆检测就可以完美运行。 但是正如你在下面的图片中看到的那样,我认为红色提取不起作用,因为相框质量差。
将原始图像转换为 HSV:
Imgproc.cvtColor(this.source, this.source, Imgproc.COLOR_RGB2HSV, 3);
提取红色:
Core.inRange(this.source, new Scalar(this.h,this.s,this.v), new Scalar(230,180,180), this.source);
所以我的问题是有没有另一种方法可以检测这样的交通标志或从中提取红色区域,顺便说一下,这些区域可能像上一张图片一样非常微弱?强>
这是原图:
这将转换为 HSV,因为您可以看到红色区域看起来与附近的树木颜色相同。这就是我想知道它是红色的,但我不能。
转换为 HSV:
这是提取的红色。如果颜色正确,我应该在标志周围得到几乎完美的圆形/椭圆,但由于颜色错误,它是不完整的。
提取后的结果:
椭圆法:
private void findEllipses(Mat input){
Mat thresholdOutput = new Mat();
int thresh = 150;
List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
MatOfInt4 hierarchy = new MatOfInt4();
Imgproc.threshold(source, thresholdOutput, thresh, 255, Imgproc.THRESH_BINARY);
//Imgproc.Canny(source, thresholdOutput, 50, 180);
Imgproc.findContours(source, contours, hierarchy, Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE);
RotatedRect minEllipse[] = new RotatedRect[contours.size()];
for(int i=0; i<contours.size();i++){
MatOfPoint2f temp=new MatOfPoint2f(contours.get(i).toArray());
if(temp.size().height > minEllipseSize && temp.size().height < maxEllipseSize){
double a = Imgproc.fitEllipse(temp).size.height;
double b = Imgproc.fitEllipse(temp).size.width;
if(Math.abs(a - b) < 10)
minEllipse[i] = Imgproc.fitEllipse(temp);
}
}
detectedObjects.clear();
for( int i = 0; i< contours.size(); i++ ){
Scalar color = new Scalar(180, 255, 180);
if(minEllipse[i] != null){
detectedObjects.add(new DetectedObject(minEllipse[i].center));
DetectedObject detectedObj = new DetectedObject(minEllipse[i].center);
Core.ellipse(source, minEllipse[i], color, 2, 8);
}
}
}
【问题讨论】:
-
你也可以上传原始(RGB)图像吗?
-
抱歉,我之前只能发布 2 个链接
-
有原图
-
谢谢。顺便说一句,将 HSV 图像渲染为 BGR 图像可能不是一个直观的提示。在 tje hsv 图像中看到绿色只是意味着 S 通道占主导地位。由于 H 通道的范围较小,因此可能没有任何意义。请尝试对 H 通道设置阈值并尝试不同的范围。
标签: android opencv detection traffic hsv