다음 이미지가 있습니다 : .OpenCV, 객체를 부분으로 나눕니다.
이 그림의 객체를 여러 부분으로 나눌 수있는 OpenCV (선호하는 Python)의 기능이 있습니까? 예를 들어, 첫 번째 객체는 두 개의 세그먼트 (또는 두 개의 라인)로 구성되며 세 번째 세그먼트는 세 개 (또는 네 개의 세그먼트)로 구성됩니다.
OpenCV에 그러한 것이없는 경우, 어디에서나 알고리즘/기능을 알면 좋을 것입니다.
다음 이미지가 있습니다 : .OpenCV, 객체를 부분으로 나눕니다.
이 그림의 객체를 여러 부분으로 나눌 수있는 OpenCV (선호하는 Python)의 기능이 있습니까? 예를 들어, 첫 번째 객체는 두 개의 세그먼트 (또는 두 개의 라인)로 구성되며 세 번째 세그먼트는 세 개 (또는 네 개의 세그먼트)로 구성됩니다.
OpenCV에 그러한 것이없는 경우, 어디에서나 알고리즘/기능을 알면 좋을 것입니다.
이 문제는 이미지를 골격화하고 HoughlinesP을 사용하여 해결할 수 있습니다. Scikit-image에는 좋은 골격 화 방법이 있습니다. 아래 그림과 같이 14 개의 선분을 찾을 수 있습니다. 마지막으로 서로 연결되어 어떤 집합이 교차하는지 찾아서 함께 속하는 것을 찾아야합니다. 변환
#!/usr/bin/python
from skimage import morphology
import cv2
import math
import numpy as np
im = cv2.imread("objects.png")
dst = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
dst = 1 - dst/255
dst = morphology.skeletonize(dst).astype(np.uint8)
objs = 255 * dst
#cv2.HoughLinesP(image, rho, theta, threshold[, lines[, minLineLength[, maxLineGap]]])
rho = 1
theta = math.pi/180
threshold = 1
minLineLength = 3
maxLineGap = 5
lines = np.ndarray([1, 1, 4, 4])
lines = cv2.HoughLinesP(dst, rho, theta, threshold, lines, minLineLength, maxLineGap)
lineColor = (0, 255, 0) # red
for line in lines[0]:
#print line
cv2.line(im, (line[0], line[1]), (line[2], line[3]), lineColor, 1, 8)
#
# Now you need to go through lines and find those that intersect
# You will notice that some lines have small gaps where they should
# join to a perpendicular line. Before find intersections you would
# need to make each line longer (just by adjusting the numbers in lines)
# to get around this problem.
#
cv2.imshow('Objects', objs)
cv2.imshow('Lines', im)
cv2.imwrite('lines.png', im)
cv2.waitKey()
cv2.destroyAllWindows()
내가 그 코드를 실행에 문제가 . 정말 많이 찾았지만 정보는 거의 찾지 못했습니다. 'code' OpenCV 오류 : 알 수없는 함수 인 파일에서 어설 션이 실패했습니다 (scn == 3 || scn == 4) .. .. .. .. .. opencv -2.4.7 \ modules \ imgproc \ src \ color.cpp 줄 3737 dst = cv2.cvtColor (im, cv2.COLOR_BGR2GRAY) cv2.error : .. \ .. \ .. \ opencv-2.4.7 \ 모듈 \ imgproc \ src \ color.cpp : 3737 : 오류 : (-215) scn == 3 || scn == 4 나는 cv2.COLOR_BGR2GRAY를 대체하려고했지만 그 결과는 같았습니다 – bdshadow
이미지가 이미 단일 채널 일 수 있으므로 'cv2.cvtColor()'를 제외 시키십시오. 즉'dst = im'을 설정하십시오. – Bull
OpenCV의 호우 라인은 도움이 될 수 있습니다 당신 http://docs.opencv.org/doc/tutorials/imgproc/imgtrans/hough_lines/hough_lines.html – Haris