호우는 훌륭하지만이 작동 할 수
조금 비싼 될 수 있습니다
-USE 임계 값 또는 검소한 이미지의 가장자리를 찾을 수 있습니다.
- 그 다음 등고선을 식별하기 위해 cvFindContours를 선택하고 직사각형을 감지하십시오. opencv 배포판의 squares.c 예제를 확인하십시오. 기본적으로 윤곽선의 폴리곤 근사값은 4 점이며이 점들 사이의 평균 각도는 90도에 가깝습니다. 다음은 squares.py 예제 (동일한 내용이지만 파이썬에서는 P입니다)의 코드 스 니펫입니다.
..some pre-processing
cvThreshold(tgray, gray, (l+1)*255/N, 255, CV_THRESH_BINARY);
# find contours and store them all as a list
count, contours = cvFindContours(gray, storage)
if not contours:
continue
# test each contour
for contour in contours.hrange():
# approximate contour with accuracy proportional
# to the contour perimeter
result = cvApproxPoly(contour, sizeof(CvContour), storage,
CV_POLY_APPROX_DP, cvContourPerimeter(contour)*0.02, 0);
res_arr = result.asarray(CvPoint)
# square contours should have 4 vertices after approximation
# relatively large area (to filter out noisy contours)
# and be convex.
# Note: absolute value of an area is used because
# area may be positive or negative - in accordance with the
# contour orientation
if(result.total == 4 and
abs(cvContourArea(result)) > 1000 and
cvCheckContourConvexity(result)):
s = 0;
for i in range(4):
# find minimum angle between joint
# edges (maximum of cosine)
t = abs(angle(res_arr[i], res_arr[i-2], res_arr[i-1]))
if s<t:
s=t
# if cosines of all angles are small
# (all angles are ~90 degree) then write quandrange
# vertices to resultant sequence
if(s < 0.3):
for i in range(4):
squares.append(res_arr[i])
- 특수 MinAreaRect2이 (주어진 2D 지점 세트에 대한 최소한의 영역의 사각형을 접하는을 검색해,), 사각형의 경계 상자를 얻을. 테두리 상자 점을 사용하면 각도를 쉽게 계산할 수 있습니다.
opencv 디렉토리에서 samples/c/아래의 C 버전 squares.c를 찾을 수도 있습니다.
컴퓨터 비전 질문을하기 때문에 몇 가지 샘플 이미지를 게시하는 것이 좋습니다. –