我有一个使用OpenCV 2.4在Android中检测交通标志速度的问题。 我的处理流程是:
"捕获帧 -> 转换为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);
}
}
}