2014-04-27 2 views
1

안녕하세요 minAreaRect에서 회전 된 rect를 그리려하고 있지만 파이썬에서만 코드를 찾습니다.opencv Java에서 minAreaRect를 그리는 방법

rect = cv2.minAreaRect(cnt) 
box = cv2.cv.BoxPoints(rect) 
box = np.int0(box) 
cv2.drawContours(im,[box],0,(0,0,255),2) 

Java로 그리는 방법은 무엇입니까? 이 같은

답변

0

뭔가 : 그래서 여기에 대한 답을 게시하기로 결정

MatOfPoint2f points = new MatOfPoint2f(new Point(1, 1), new Point(5, 1), new Point(4, 3), new Point(6, 2)); 
RotatedRect rrect = Imgproc.minAreaRect(points); 
+2

답해 주셔서 감사합니다.하지만 minAreaRect에서 결과 윤곽을 그려야합니다. – kosbou

2

나는이 질문은 오래 알고 있지만, 최근에 내가 같은 문제가 있었다.

안타깝게도 Android에서 사용하지 않는 OpenCV 버전은 이며 매개 변수로 RotatedRect을 지원합니다. 그래서 나는 즉시해야만했다.

rRect = Imgproc.minAreaRect(mop2f); 

     Point[] vertices = new Point[4]; 
     rRect.points(vertices); 
     for (int j = 0; j < 4; j++){ 
      Imgproc.line(mat, vertices[j], vertices[(j+1)%4], new Scalar(0,255,0)); 
     } 
1

는이 같은 코드를 사용하여 minAreaRect에서 회전하는 구형을 그릴 그릴 수있는이 방법을

Point[] vertices = new Point[4]; 
rotatedRect.points(vertices); 
List<MatOfPoint> boxContours = new ArrayList<>(); 
boxContours.add(new MatOfPoint(vertices)); 
Imgproc.drawContours(out, boxContours, 0, new Scalar(128, 128, 128), -1); 

을 등고선을 채우고 단색으로 채우십시오 (Imgproc.line을 사용하면 할 수없는 것).

1

당신은이 같은 drawContours 사용할 수 있습니다 :

Point points[] = new Point[4]; 
    rect.points(points); 
    for(int i=0; i<4; ++i){ 
     Core.line(init, points[i], points[(i+1)%4], new Scalar(255,255,255)); 
    } 
관련 문제