0
: 나는 인쇄 할 때OpenCV의 파이썬 인식을 형성 (나쁜 화질) 나는 이미지의 특정 모양을 감지하기 위해 다음 코드를 사용하고
import cv2
import numpy as np
img = cv2.imread("006.jpg")
grey = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
ret,thresh = cv2.threshold(grey,127,255,1)
cv2.imshow('img',thresh)
cv2.waitKey(0)
contours, h = cv2.findContours(thresh, 1, cv2.CHAIN_APPROX_SIMPLE)
contours.sort(key = len)
for contour in contours:
approx = cv2.approxPolyDP(contour, 0.01*cv2.arcLength(contour, True), True)
#star - > yellow
if len(approx) == 10:
cv2.drawContours(img, [contour],0, (0,255,255), -1)
#circle -> black
elif len(approx) >= 11:
cv2.drawContours(img, [contour], 0, (0,0,0), -1)
#triangle -> green
elif len(approx) == 3:
cv2.drawContours(img,[contour],0,(0,255,0),-1)
#square -> blue
elif len(approx) == 4:
cv2.drawContours(img, [contour],0, (255,0,0),-1)
#pentagon -> red
elif len(approx) == 5:
cv2.drawContours(img, [contour],0, (0,0,255), -1)
cv2.imshow('img',img)
cv2.waitKey(0)
이 코드는 내 컴퓨터에 이미지를 잘 작동하지만, 이미지를 찍은 후 코드를 다시 실행 해보십시오 (예 : image). 그래야 제대로 작동하지 않습니다.
나는 블러와 카니를 사용하여 이미 시도했지만 두 번째 사진을 충분히 부드럽게 만들 수는 없습니다.
누군가 도와 드릴 수 있기를 바랍니다.
답변 해 주셔서 감사합니다. 오츠 방법은 나를 위해 잘 작동하지는 않았지만 적응 형 임계 값 지정과 캐니 함수를 사용하여 해결했습니다. –