OpenCV在椭圆上获取像素
我正在尝试从图像中获取椭圆的像素。
例如,我在随机图像上绘制一个椭圆(示例 geeksforgeeks 代码):
import cv2
path = r'C:\Users\Rajnish\Desktop\geeksforgeeks\geeks.png'
image = cv2.imread(path)
window_name = 'Image'
center_coordinates = (120, 100)
axesLength = (100, 50)
angle = 0
startAngle = 0
endAngle = 360
color = (0, 0, 255)
thickness = 5
image = cv2.ellipse(image, center_coordinates, axesLength,
angle, startAngle, endAngle, color, thickness)
cv2.imshow(window_name, image)
现在,我想获取椭圆边界线的像素值。如果可能的话,我想使用 cv2.ellipse() 获取椭圆的像素作为坐标数组。
任何人都可以帮我解决这个问题吗?
I'm trying to get the pixels of an ellipse from an image.
For example, I draw an ellipse on a random image (sample geeksforgeeks code):
import cv2
path = r'C:\Users\Rajnish\Desktop\geeksforgeeks\geeks.png'
image = cv2.imread(path)
window_name = 'Image'
center_coordinates = (120, 100)
axesLength = (100, 50)
angle = 0
startAngle = 0
endAngle = 360
color = (0, 0, 255)
thickness = 5
image = cv2.ellipse(image, center_coordinates, axesLength,
angle, startAngle, endAngle, color, thickness)
cv2.imshow(window_name, image)
Now, I want to get the pixel value of boundary line of ellipse. If it is possible I would like to get the pixel of ellipse using cv2.ellipse() back as an array of coordinates.
Can anyone help me with this please.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果要在椭圆上获取点(位置),则可以使用
ellipse2poly()
函数。如果
ellipse2poly()
的参数类型是不便的,则自己计算是最方便的方法。该示例代码为C ++,但计算出的是明确的。
If you want to obtain points (locations) on an ellipse, you can use
ellipse2Poly()
function.If the argument type of
ellipse2Poly()
is inconvenient, calculating by yourself is most convenient way.This sample code is C ++, but what calculated is clear.
There is no direct OpenCV way probably to get these points of the ellipse but you can extract your points via indirect way like this:
contour
will store the outer points of your red ellipse.在这里,我所做的是创建椭圆形的掩码图像,并找到了所需的最外部轮廓点。
There is no direct OpenCV way probably to get these points of the ellipse but you can extract your points via indirect way like this:
contour
will store the outer points of your red ellipse.Here, what I have done is created a mask image of the ellipse and found the externalmost contour's points that is the required thing.