[英]In android how do I count the number of lines in a image using openCV
这是我尝试的方法。我将输出作为Imageview对象的img2中的灰度图像输出。
问题在于lines.cols()将所有内容都视为一行。
我希望计数准确地如第一张图所示(我的意思是分隔停车场的行,汽车可以在其中占用的行)中显示的较大行数。 我的输出图像有人可以指导我如何获取确切的停车位我使用过openCV 2.4版,过去2天我一直在努力
public String getCount() {
Bitmap bitmap = BitmapFactory.decodeResource(getApplicationContext().getResources(), R.drawable.park);
mat = new Mat();
edges = new Mat();
Mat mRgba = new Mat(612, 816, CvType.CV_8UC1);
Mat lines = new Mat();
Utils.bitmapToMat(bitmap, mat);
Imgproc.Canny(mat, edges, 50, 90);
int threshold = 50;
int minLineSize = 20;
int lineGap = 20;
Imgproc.HoughLinesP(edges, lines, 1, Math.PI / 180, threshold, minLineSize, lineGap);
int count = lines.cols();
int coun= lines.rows();
System.out.println("count = " + count);
System.out.println("coun = " + coun);
String cou = String.valueOf(count);
for (int x = 0; x < lines.cols(); x++) {
double[] vec = lines.get(0, x);
double x1 = vec[0],
y1 = vec[1],
x2 = vec[2],
y2 = vec[3];
Point start = new Point(x1, y1);
Point end = new Point(x2, y2);
Core.line(mRgba, start, end, new Scalar(255, 0, 0), 3);
}
Bitmap bmp = Bitmap.createBitmap(mRgba.cols(), mRgba.rows(), Bitmap.Config.ARGB_8888);
Utils.matToBitmap(mRgba, bmp);
bitmap = bmp;
Drawable d = new BitmapDrawable(Resources.getSystem(), bitmap);
img2.setImageDrawable(d);
return cou;
}
您应该修改有关OpenCV计数的众多答案之一,其中每种不同情况下的检测类型都不同。 您应该为停车线制作自己的模型。 检查其中的一些方法/检测器Haar级联分类器 , 潜在的SVM或Word of Bag 。
您还可以修改一些对其他东西有用的答案,例如下面对于硬币的答案,只有您应该搜索停车线的形状而不是硬币:
http://answers.opencv.org/question/36111/how-to-count-number-of-coins-in-android-opencv/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.