Convert Vec4i to Java openCV

I am new to OpenCV on Android. I am trying to hide C ++ code in Java. I was stuck at some point that I can not 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 .. to 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];
    }

I'm confused with is inside the for loop. when converting strings to an array, it gives an int array. But inside the for loop, v is again defined, which should be an array. I did not understand this. Can someone please help me get through this. Thank you in advance.

+4
source share
1 answer

Finally, I managed to write working code. using 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);

    }
+10
source

All Articles