2014-11-09 1 views
0

enter image description here 안드로이드에서 OpenCV의 도움으로 회선의 좌표를 지정하고 싶습니다. 나는 자습서를 공부하고이 내 API를 호출 안드로이드에서 OpenCv의 도움으로 회선의 좌표를 얻는 방법

Mat ImageMat = new Mat(croppedImage.getHeight(), croppedImage.getWidth(), CvType.CV_8U, new Scalar(4)); 
int threshold = 50; 
int minLineSize = 100; 
int lineGap = 20; 

Mat lines = new Mat(); 
Imgproc.HoughLinesP(ImageMat, lines, 1, Math.PI/180, threshold, minLineSize, lineGap); 

내가 그것을 하나 개의 라인으로 만 "라인"변수 I는 좌표의 수백을 얻을 수있는 간단한 이미지를 제공하는 것입니다 것입니다. 그 한 줄의 좌표는 단지 ​​하나뿐입니다. 그 한 줄의 좌표 만 얻는 법. 또한 minLineSize가 측정되는 단위는 무엇입니까? 내 줄은 성, 성 등 앞에있는 줄입니다.

+0

아마 너의 선이 너무 두꺼워서 두꺼운 선에서 너비가 넓은 선들을 많이 볼 수있을 것이다. origibal 이미지를 게시하고 가능하면 검출 된 모든 선이 그려진 이미지를 게시하십시오. – Micka

+0

minLineSize는 픽셀 거리로 측정해야합니다 (아마도 유클리드 또는 대략 유클리드). – Micka

+0

@Micka 이미지가 이제 질문입니다. –

답변

0

다음은 C++의 코드입니다. 당신이 볼 수있는

enter image description here

, 원하는 :이 출력을 얻을 귀하의 의견과

int main() 
{ 
    // loading your image. you dont need theses parts 
    cv::Mat input = cv::imread("../inputData/FormularLineDetection.png"); 


    // convert to grayscale: you will do something similar: 
    cv::Mat gray; 
    cv::cvtColor(input, gray, CV_BGR2GRAY); 

    // computation of binary thresholding so that dark areas of the image will bevcome "foreground pixel". 
    // If your image have bright features you'll have to choose different parameters. 
    // If you want to detect contour lines instead you'll compute gradient magnitude first. 
    cv::Mat mask; 
    cv::threshold(gray, mask, 0, 255, CV_THRESH_BINARY_INV | CV_THRESH_OTSU); 

    std::vector<cv::Vec4i> lines; 
    //cv::HoughLinesP(mask, lines, 1, CV_PI/180.0, 50, 50, 10); 
    // I've changed the min-Size of a line to 1/3 of the images width. Maybe you'll have to adjust that parameter to your needs! 
    cv::HoughLinesP(mask, lines, 1, CV_PI/180.0, 50, input.cols/3, 10); 



    // draw the lines to visualize: you might not do this at all 
    for(size_t i = 0; i < lines.size(); i++) 
    { 
     cv::Vec4i l = lines[i]; 
     cv::line(input, cv::Point(l[0], l[1]), cv::Point(l[2], l[3]), cv::Scalar(0,0,255), 3, CV_AA); 
    } 

    // display and save to disk 
    cv::imshow("mask", mask); // you might not want to display the image here. 
    cv::imshow("output",input); 
    cv::imwrite("../outputData/FormularLineDetection.png", input); 

    cv::waitKey(0); 
    return 0; 
} 

: 대부분 OpenCV의 기능을 사용하고 있기 때문에, 당신은 쉽게 안드로이드 CV 할 포트 수있을 것 선이 감지되지만 큰 두께의 "선"도 감지됩니다. 그런 구조를 감지하고 걸러 낼 수 있습니다.