转换Vec4i到Java的OpenCV [英] Convert Vec4i to Java openCV

查看:2214
本文介绍了转换Vec4i到Java的OpenCV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的OpenCV在Android中。我想一个隐蔽的C ++ code到Java。我被困在某个时刻,我不能继续下去。

I'm new to OpenCV in Android. I'm trying to covert a C++ code into Java. I am stuck in some point that I cannot continue.

std::vector<cv::Vec4i> lines;
cv::HoughLinesP(bw, lines, 1, CV_PI/180, 70, 30, 10);

    // Expand the lines
    for (int i = 0; i < lines.size(); i++)
    {
        cv::Vec4i v = lines[i];
        lines[i][0] = 0;
        lines[i][1] = ((float)v[1] - v[3]) / (v[0] - v[2]) * -v[0] + v[1]; 
        lines[i][2] = src.cols; 
        lines[i][3] = ((float)v[1] - v[3]) / (v[0] - v[2]) * (src.cols - v[2]) + v[3];
    }

中途我转换..高达待办事项

half way I converted.. upto the TODO

MatOfInt4 lines= new MatOfInt4();
Imgproc.HoughLinesP(bw, lines, 1, Math.PI/180, 70, 30, 10);

int[] lineArray = lines.toArray();
// Expand the lines
//TODO 


 for (int i = 0; i < lineArray.length; i++)
    {
        int v = lineArray[i];
        lines.[i][0] = 0;
        lines[i][1] = ((float)v[1] - v[3]) / (v[0] - v[2]) * -v[0] + v[1]; 
        lines[i][2] = src.cols(); 
        lines[i][3] = ((float)v[1] - v[3]) / (v[0] - v[2]) * (src.cols() - v[2]) + v[3];
    }

我很困惑里面的for循环。在转换线条时的一个数组它给出了一个int数组。但是里面的for循环再次V置定义这应该是一个数组。我没有得到这一点。任何人都可以请帮我通过这个来获得。谢谢你在前进。

which I'm confused is inside the for loop. when converted lines in to a Array it gives a int array. But inside the for loop again v is defined which should be a array. I didn't get this point. Can anybody please help me to get through this. Thank you in advance.

推荐答案

最后,我设法写工作code。与帮助这个链接

Finally I managed to write the working code. with help of this link

    Mat lines = new Mat();
    int threshold = 70;
    int minLineSize = 30;
    int lineGap = 10;

    Imgproc.HoughLinesP(thresholdImage, lines, 1, Math.PI / 180, threshold,
            minLineSize, lineGap);

    for (int x = 0; x < lines.cols(); x++) {

        double[] vec = lines.get(0, x);
        double[] val = new double[4];

        val[0] = 0;
        val[1] = ((float) vec[1] - vec[3]) / (vec[0] - vec[2]) * -vec[0] + vec[1];
        val[2] = src.cols();
        val[3] = ((float) vec[1] - vec[3]) / (vec[0] - vec[2]) * (src.cols() - vec[2]) + vec[3];

        lines.put(0, x, val);

    }

这篇关于转换Vec4i到Java的OpenCV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆