Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用android和opencv检测道路车道_Android_Opencv - Fatal编程技术网

使用android和opencv检测道路车道

使用android和opencv检测道路车道,android,opencv,Android,Opencv,我的手机无法检测道路车道。 我写了一些道路车道检测代码,但他不为我工作。 从相机得到修改,从正常视图到BGR颜色,并尝试使用高斯模糊和Canny,但我认为我不善于绘制检测车道。 也许有些人有另一个想法,如何使用OpenCV检测道路车道 Mat mYuv = new Mat(height + height / 2, width, CvType.CV_8UC1); Mat mRgba = new Mat(height + height / 2, width, CvType.CV_8UC1); Mat

我的手机无法检测道路车道。 我写了一些道路车道检测代码,但他不为我工作。 从相机得到修改,从正常视图到BGR颜色,并尝试使用高斯模糊和Canny,但我认为我不善于绘制检测车道。 也许有些人有另一个想法,如何使用OpenCV检测道路车道

Mat mYuv = new Mat(height + height / 2, width, CvType.CV_8UC1);
Mat mRgba = new Mat(height + height / 2, width, CvType.CV_8UC1);
Mat thresholdImage = new Mat(height + height / 2, width, CvType.CV_8UC1);
mYuv.put(0, 0, data);
Imgproc.cvtColor(mYuv, mRgba, Imgproc.COLOR_YUV420p2BGR, 4);
//convert to grayscale
Imgproc.cvtColor(mRgba, thresholdImage, Imgproc.COLOR_mRGBA2RGBA, 4);
// Perform a Gaussian blur (convolving in 5x5 Gaussian) & detect edges
Imgproc.GaussianBlur(mRgba, mRgba, new Size(5,5), 2.2, 2);
Imgproc.Canny(mRgba, thresholdImage, VActivity.CANNY_MIN_TRESHOLD, VActivity.CANNY_MAX_THRESHOLD);
Mat lines = new Mat();
double rho = 1;
double theta = Math.PI/180;
int threshold = 50;
//do Hough transform to find lanes
Imgproc.HoughLinesP(thresholdImage, lines, rho, theta, threshold, VActivity.HOUGH_MIN_LINE_LENGTH, VActivity.HOUGH_MAX_LINE_GAP);
for (int x = 0; x < lines.cols() && x < 1; 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);
}
Mat mYuv=新垫(高度+高度/2,宽度,CvType.CV_8UC1);
材料mRgba=新材料(高度+高度/2,宽度,CvType.CV_8UC1);
Mat thresholdImage=新的Mat(高度+高度/2,宽度,CvType.CV_8UC1);
mYuv.put(0,0,数据);
Imgproc.cvtColor(mYuv,mRgba,Imgproc.COLOR_YUV420p2BGR,4);
//转换为灰度
cvtColor(mRgba,thresholdImage,Imgproc.COLOR_mRGBA2RGBA,4);
//执行高斯模糊(5x5高斯卷积)&检测边缘
GaussianBlur(mRgba,mRgba,新尺寸(5,5),2.2,2);
Imgproc.Canny(mRgba,thresholdImage,VActivity.Canny\u MIN\u TRESHOLD,VActivity.Canny\u MAX\u THRESHOLD);
垫线=新垫();
双rho=1;
双θ=Math.PI/180;
int阈值=50;
//进行Hough变换以查找车道
Imgproc.HoughLinesP(阈值图像、线、ρ、θ、阈值、VActivity.HOUGH_最小线长度、VActivity.HOUGH_最大线间距);
对于(int x=0;x
这种方法很好,我也做过类似的事情,不是用于道路线检测,但我确实注意到它可以用于此目的。一些评论:

不知道你为什么这么做:

Imgproc.cvtColor(mRgba, thresholdImage, Imgproc.COLOR_mRGBA2RGBA, 4);
作为1。评论说,转换为灰度,这是一个单一的渠道和2。thresholdImage稍后将被Canny调用覆盖。您只需使用以下工具对thresholdImage进行尺寸标注:

thresholdImage = new Mat(mRgba.size(), CvType.CV_8UC1);
您对Canny调用的参数值是什么?我对我的进行了大量的研究,最终得到了如下值:threshold1=441,threshold2=160,光圈=3

同样,Imgproc.HoughLinesP:我使用Imgproc.HoughLines而不是Imgproc.HoughLinesP,参数为:threshold=80,minLen=30,maxLen=10

另外,请看:

for (int x = 0; x < lines.cols() && x < 1; x++){
这将返回一个介于-PI/2和PI/2之间的弧度角度

关于Canny参数,然后我会进行实验——我设置了onTouch,这样我可以通过触摸屏幕的某些部分来调整阈值,以实时查看效果。请注意,光圈是一个相当令人失望的参数:它似乎只喜欢奇数值3、5和7,而3是我发现的最好值

类似于onTouch方法:

int w = mRgba.width();
int h = mRgba.height();

float x = event.getX();
float y = event.getY();

if ((x < w / 3) && (y < h / 2)) t1 += 20;
if ((x < w / 3) && (y >= h / 2)) t1 -= 20;
if ((x > 2 * w / 3) && (y < h / 2)) t2 += 20;
if ((x > 2 * w / 3) && (y >= h / 2)) t2 -= 20;
intw=mRgba.width();
inth=mRgba.height();
float x=event.getX();
float y=event.getY();
如果((x=h/2))t1-=20;
如果((x>2*w/3)和&(y2*w/3)和&(y>=h/2))t2-=20;

t1和t2是传递给Canny调用的阈值。

这种方法很好,我也做了类似的事情,不是用于道路线检测,但我注意到它可以用于此目的。一些评论:

不知道你为什么这么做:

Imgproc.cvtColor(mRgba, thresholdImage, Imgproc.COLOR_mRGBA2RGBA, 4);
作为1。评论说,转换为灰度,这是一个单一的渠道和2。thresholdImage稍后将被Canny调用覆盖。您只需使用以下工具对thresholdImage进行尺寸标注:

thresholdImage = new Mat(mRgba.size(), CvType.CV_8UC1);
您对Canny调用的参数值是什么?我对我的进行了大量的研究,最终得到了如下值:threshold1=441,threshold2=160,光圈=3

同样,Imgproc.HoughLinesP:我使用Imgproc.HoughLines而不是Imgproc.HoughLinesP,参数为:threshold=80,minLen=30,maxLen=10

另外,请看:

for (int x = 0; x < lines.cols() && x < 1; x++){
这将返回一个介于-PI/2和PI/2之间的弧度角度

关于Canny参数,然后我会进行实验——我设置了onTouch,这样我可以通过触摸屏幕的某些部分来调整阈值,以实时查看效果。请注意,光圈是一个相当令人失望的参数:它似乎只喜欢奇数值3、5和7,而3是我发现的最好值

类似于onTouch方法:

int w = mRgba.width();
int h = mRgba.height();

float x = event.getX();
float y = event.getY();

if ((x < w / 3) && (y < h / 2)) t1 += 20;
if ((x < w / 3) && (y >= h / 2)) t1 -= 20;
if ((x > 2 * w / 3) && (y < h / 2)) t2 += 20;
if ((x > 2 * w / 3) && (y >= h / 2)) t2 -= 20;
intw=mRgba.width();
inth=mRgba.height();
float x=event.getX();
float y=event.getY();
如果((x=h/2))t1-=20;
如果((x>2*w/3)和&(y2*w/3)和&(y>=h/2))t2-=20;

t1和t2是传递给Canny调用的阈值。

这种方法很好,我也做了类似的事情,不是用于道路线检测,但我注意到它可以用于此目的。一些评论:

不知道你为什么这么做:

Imgproc.cvtColor(mRgba, thresholdImage, Imgproc.COLOR_mRGBA2RGBA, 4);
作为1。评论说,转换为灰度,这是一个单一的渠道和2。thresholdImage稍后将被Canny调用覆盖。您只需使用以下工具对thresholdImage进行尺寸标注:

thresholdImage = new Mat(mRgba.size(), CvType.CV_8UC1);
您对Canny调用的参数值是什么?我对我的进行了大量的研究,最终得到了如下值:threshold1=441,threshold2=160,光圈=3

同样,Imgproc.HoughLinesP:我使用Imgproc.HoughLines而不是Imgproc.HoughLinesP,参数为:threshold=80,minLen=30,maxLen=10

另外,请看:

for (int x = 0; x < lines.cols() && x < 1; x++){
这将返回一个介于-PI/2和PI/2之间的弧度角度

关于Canny参数,然后我会进行实验——我设置了onTouch,这样我可以通过触摸屏幕的某些部分来调整阈值,以实时查看效果。请注意,光圈是一个相当令人失望的参数:它似乎只喜欢奇数值3、5和7,而3是我发现的最好值

类似于onTouch方法:

int w = mRgba.width();
int h = mRgba.height();

float x = event.getX();
float y = event.getY();

if ((x < w / 3) && (y < h / 2)) t1 += 20;
if ((x < w / 3) && (y >= h / 2)) t1 -= 20;
if ((x > 2 * w / 3) && (y < h / 2)) t2 += 20;
if ((x > 2 * w / 3) && (y >= h / 2)) t2 -= 20;
intw=mRgba.width();
inth=mRgba.height();
float x=event.getX();
float y=event.getY();
如果((x