2017-02-13 3 views
0

my photo is here.이 사진의 타원 부분 (접시)을 감지하고 Opencv의 다른 사진에 가면 더 나은 해결책이나 알고리즘을 찾고 있습니다. 몇 가지 조언이나 해결책을 제공해 주시겠습니까? 내 코드는 다음과 같습니다opencv python의 타원 감지

circles = cv2.HoughCircles(img, cv2.HOUGH_GRADIENT, 1.2, 1, param1=128, minRadius=200, maxRadius=600) 
    # draw detected circles on image 
    circles = circles.tolist() 
    for cir in circles: 
     for x, y, r in cir: 
      x, y, r = int(x), int(y), int(r) 
      cv2.circle(img, (x, y), r, (0, 255, 0), 4) 

    # show the output image 
    cv2.imshow("output", cv2.resize(img, (500, 500))) 
+1

당신에게 "이름"

그들의 코드는 here를 찾을 수 있습니다 또는 사본으로/아래 붙여 ... scikit 이미지를 설치하고 그것에게 주사를 여기서 타원 탐지가 필요 없습니다 (btw, OpenCV에서 사용 가능하지 않음). 밝은 값에 간단한 임계 값을 설정하고 가장 큰 연결 구성 요소를 유지하는 것이 좋습니다. 또한 시도한 것을 보여주십시오. – Miki

+0

단순한 색상 분할이 효과가있을 수 있습니다. – ZdaR

+0

나는 내 질문에 연결된 코드의 특별한 부분을 추가하고있다. plz처럼 보시 겠어? –

답변

1

skimage에 대한 대체 Xie, Yonghong, and Qiang Ji에 의해 만들어로 게시가있다 ...

"새로운 효율적인 타원 검출 방법."패턴 인식, 2002 년 절차. 에 관한 제 16 차 국제 회의. Vol. 2. IEEE, 2002.

타원 검출 코드는 상대적으로 느리고 예제는 약 70 초 걸립니다. "28 초"라고 주장한 웹 사이트와 비교할 때 당신이 CONDA 또는 핍이있는 경우

:

import matplotlib.pyplot as plt 

from skimage import data, color, img_as_ubyte 
from skimage.feature import canny 
from skimage.transform import hough_ellipse 
from skimage.draw import ellipse_perimeter 

# Load picture, convert to grayscale and detect edges 
image_rgb = data.coffee()[0:220, 160:420] 
image_gray = color.rgb2gray(image_rgb) 
edges = canny(image_gray, sigma=2.0, 
       low_threshold=0.55, high_threshold=0.8) 

# Perform a Hough Transform 
# The accuracy corresponds to the bin size of a major axis. 
# The value is chosen in order to get a single high accumulator. 
# The threshold eliminates low accumulators 
result = hough_ellipse(edges, accuracy=20, threshold=250, 
         min_size=100, max_size=120) 
result.sort(order='accumulator') 

# Estimated parameters for the ellipse 
best = list(result[-1]) 
yc, xc, a, b = [int(round(x)) for x in best[1:5]] 
orientation = best[5] 

# Draw the ellipse on the original image 
cy, cx = ellipse_perimeter(yc, xc, a, b, orientation) 
image_rgb[cy, cx] = (0, 0, 255) 
# Draw the edge (white) and the resulting ellipse (red) 
edges = color.gray2rgb(img_as_ubyte(edges)) 
edges[cy, cx] = (250, 0, 0) 

fig2, (ax1, ax2) = plt.subplots(ncols=2, nrows=1, figsize=(8, 4), sharex=True, 
           sharey=True, 
           subplot_kw={'adjustable':'box-forced'}) 

ax1.set_title('Original picture') 
ax1.imshow(image_rgb) 

ax2.set_title('Edge (white) and result (red)') 
ax2.imshow(edges) 

plt.show() 
2

접근법 1 : 미키에 의해 제안

, 나는 (이 내가이 지역 속성을 사용) 윤곽 속성을 사용하여 지정된 이미지에서 타원을 감지 할 수 있었다 .

CODE :

#--- First obtain the threshold using the greyscale image --- 
ret,th = cv2.threshold(gray,127,255, 0) 

#--- Find all the contours in the binary image --- 
_, contours,hierarchy = cv2.findContours(th,2,1) 
cnt = contours 
big_contour = [] 
max = 0 
for i in cnt: 
    area = cv2.contourArea(i) #--- find the contour having biggest area --- 
    if(area > max): 
     max = area 
     big_contour = i 

final = cv2.drawContours(img, big_contour, -1, (0,255,0), 3) 
cv2.imshow('final', final) 

이 내가 얻은 것입니다 :

enter image description here

접근법 2 :

또한이 경우에 당신에 의해 제안 된 방법을 사용할 수 있습니다. 타원/원의 탐지.

이미지를 사전 처리해야합니다. 나는 적응 임계 값을 수행하고이 얻을 :

enter image description here

지금이 이미지에 호우 원 검출을 수행 할 수 있습니다.

희망이 없다! : D

+0

도움을 주셔서 고맙습니다. 그러나 제 문제는 윤곽선을 사용할 수 없습니다. 영역 메서드 HoughCircles로 변환하려고하는데 내 문제는 내 주변에 타원을 그릴 수 없다는 것입니다. 저를 도와 주시겠습니까? 이 알고리즘으로 어떻게 할 수 있습니까? 미리 감사드립니다. –

+0

게시 한 두 번째 이미지에서 Hough transform을 사용하여 원을 감지해볼 수 있습니다. 그것을 시도해보십시오 –

+1

조금 힌트 : HoughCircles는 생략 부호를 찾지 않습니다 ... 그냥 동그라미;) @Moh – Miki