【问题标题】:Dividing a circle into 12 equal parts using OpenCV and Python使用 OpenCV 和 Python 将一个圆分成 12 个相等的部分
【发布时间】:2020-04-20 21:44:27
【问题描述】:

我有这张图片

使用霍夫变换,我在目标上画圈,这是代码和结果

import cv2
import numpy as np
from matplotlib import pyplot as plt
import math

bgr_img = cv2.imread('16-Bit_ID-00001.jpg') # read as it is

if bgr_img.shape[-1] == 3:           # color image
    b,g,r = cv2.split(bgr_img)       # get b,g,r
    rgb_img = cv2.merge([r,g,b])     # switch it to rgb
    gray_img = cv2.cvtColor(bgr_img, cv2.COLOR_BGR2GRAY)
else:
    gray_img = bgr_img

img = cv2.medianBlur(gray_img, 95)     # blur value acts as a filter
cimg = cv2.cvtColor(img,cv2.COLOR_GRAY2BGR)

circles = cv2.HoughCircles(img,cv2.HOUGH_GRADIENT,1,30,
                            param1=50,param2=50,minRadius=60,maxRadius=0)

circles = np.uint16(np.around(circles))

for i in circles[0,:]:
    # draw the outer circle
    cv2.circle(cimg,(i[0],i[1]),i[2],(0,255,0),2)
    # draw the center of the circle
    cv2.circle(cimg,(i[0],i[1]),2,(0,0,255),3)
    #sliceno = np.int32((math.pi + np.arctan2(Y, X)) * (N / (2 * math.pi)))

plt.subplot(121),plt.imshow(rgb_img)
plt.title('Input Image'), plt.xticks([]), plt.yticks([])
plt.subplot(122),plt.imshow(cimg)
plt.title('Hough Transform'), plt.xticks([]), plt.yticks([])
plt.show()

我得到的结果是

现在我想将霍夫变换形成的圆分成 12 个相等的部分。 有人知道怎么做吗?

【问题讨论】:

  • 分割是什么意思 - 用 12 个圆圈创建分割线或使用圆圈制作 12 个不同的对象?
  • 12个不同的对象使用圆圈,这个
  • 会将圆圈分成 12 个相等的部分以确定右侧挤压的位置(有点像时钟手柄/设置旋钮?)出于好奇,图像代表什么? (看起来很有趣)
  • 这是一个使用二进制数制作的编码目标。右手边的挤压有代码,所以当我们把圆分成12等份时,我们再写每12份的二进制代码。就像右边挤压出来的弧会得到 1 而黑色区域上的弧会得到 0。我们会得到一些东西(01111000000)
  • George Profenza 你知道如何将圆分成 12 等份吗?

标签: python opencv image-processing computer-vision photogrammetry


【解决方案1】:

我做了一个尝试,但它远非完美,也不是我想做的,但它仍然在这里

import cv2
import numpy as np
from matplotlib import pyplot as plt
import math

bgr_img = cv2.imread('16-Bit_ID-00001.jpg') # read as it is

if bgr_img.shape[-1] == 3:           # color image
    b,g,r = cv2.split(bgr_img)       # get b,g,r
    rgb_img = cv2.merge([r,g,b])     # switch it to rgb
    gray_img = cv2.cvtColor(bgr_img, cv2.COLOR_BGR2GRAY)
else:
    gray_img = bgr_img

img = cv2.medianBlur(gray_img, 95)     # blur value acts as a filter
cimg = cv2.cvtColor(img,cv2.COLOR_GRAY2BGR)

circles = cv2.HoughCircles(img,cv2.HOUGH_GRADIENT,1,30,
                            param1=50,param2=50,minRadius=60,maxRadius=0)

circles = np.uint16(np.around(circles))
angle = 0
for i in circles[0,:]:
    # draw the outer circle
 cv2.circle(cimg,(i[0],i[1]),i[2],(0,255,0),2)
    # draw the center of the circle
 cv2.circle(cimg,(i[0],i[1]),2,(0,0,255),3)
    # dividing the circle into 12 equal parts
 (x, y), radius = (i[0],i[1]),i[2]

 radius = int(radius)
 angle = angle +30
 x_2 = int(round(x + radius * math.cos(angle * math.pi / 180.0)));
 y_2 = int(round(y + radius * math.sin(angle * math.pi / 180.0)));



 cv2.line(cimg, (i[0],i[1]),(x_2,y_2),(255,127,0),3,cv2.LINE_AA)
 angle = angle +30
 x_2 = int(round(x + radius * math.cos(angle * math.pi / 180.0)));
 y_2 = int(round(y + radius * math.sin(angle * math.pi / 180.0)));



 cv2.line(cimg, (i[0],i[1]),(x_2,y_2),(255,127,0),3,cv2.LINE_AA)

plt.subplot(121),plt.imshow(rgb_img)
plt.title('Input Image'), plt.xticks([]), plt.yticks([])
plt.subplot(122),plt.imshow(cimg)
plt.title('Hough Transform'), plt.xticks([]), plt.yticks([])
plt.show()

这是结果

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-09-17
    • 1970-01-01
    • 1970-01-01
    • 2012-01-07
    • 2017-05-28
    • 1970-01-01
    • 2016-10-10
    • 1970-01-01
    相关资源
    最近更新 更多