将OpenCv C ++代码转换为Java

时间:2016-01-13 17:52:11

标签: java c++ opencv

我正在尝试使用OpenCV houghLine算法检测Image中的行,但问题是我发现的唯一的教程是在C ++中,我设法将一些代码转换为Java但是有些行太混乱了,下面是原始代码我正在转换为Java

  Mat dst, cdst;
Canny(src, dst, 50, 200, 3); 
cvtColor(dst, cdst, CV_GRAY2BGR); 

vector<Vec2f> lines;
// detect lines
HoughLines(dst, lines, 1, CV_PI/180, 150, 0, 0 );

// draw lines
for( size_t i = 0; i < lines.size(); i++ )
{
    float rho = lines[i][0], theta = lines[i][1];
    Point pt1, pt2;
    double a = cos(theta), b = sin(theta);
    double x0 = a*rho, y0 = b*rho;
    pt1.x = cvRound(x0 + 1000*(-b));
    pt1.y = cvRound(y0 + 1000*(a));
    pt2.x = cvRound(x0 - 1000*(-b));
    pt2.y = cvRound(y0 - 1000*(a));
    line( cdst, pt1, pt2, Scalar(0,0,255), 3, CV_AA);
}

这就是我到目前为止所做的事情

       Mat dst, cdst;
    Imgproc.Canny(src, dst, 50, 200); 
  //  Imgproc.Canny(src, dst, 50, 200, 3); 
    Imgproc.cvtColor(dst, cdst, Imgproc.COLOR_GRAY2BGRA); 

    Vector<Vec2f> lines;
    // detect lines
    Imgproc.HoughLines(dst, lines, 1, Math.PI/180, 150, 0, 0 );

    // draw lines
    for( int i = 0; i < lines.size(); i++ )
    {
        float rho = lines[i][0], theta = lines[i][1];
        Point pt1, pt2;
        double a = Math.cos(theta), b = Math.sin(theta);
        double x0 = a*rho, y0 = b*rho;
        pt1.x = Math.round(x0 + 1000*(-b));
        pt1.y = Math.round(y0 + 1000*(a));
        pt2.x = Math.round(x0 - 1000*(-b));
        pt2.y = Math.round(y0 - 1000*(a));
        Imgproc.line( cdst, pt1, pt2, new Scalar(0,0,255), 3, Core.LINE_AA);
        //Imgproc.line( cdst, pt1, pt2, new Scalar(0,0,255), 3, Core.LINE_AA);
    }

我的问题从第3行Imgproc.Canny(src, dst, 50, 200, 3)开始,我发现5个参数的Canny的Java版本有boolean作为其第5个参数,Vector<Vec2f> lines我无法找到Vec2f在Java Version和Imgproc.line( cdst, pt1, pt2, new Scalar(0,0,255), 3, Core.LINE_AA)中,Imgproc行中没有6参数的方法,我找到的最接近的参数是5和7

0 个答案:

没有答案