确定对象是向上还是向下

2024-05-14 05:57:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图确定这个物体是向上还是向下。 问题对象:Part to help visualize(用手机拍摄)

问题:我无法确定零件是从右侧向上翻转还是从右侧向下翻转

带有背光的是使用cv2.Minareact裁剪的,因此这是相机所看到的真实分辨率

工作区:

  • 摄像机分辨率:2592(高)×1944(伏)
  • 相机位于托盘上方15-18英寸(可移动)
  • 2个托盘并排,两个6x9英寸,带 背光

Hump Down <<&书信电报;此图像没有局部照明,驼峰向下。这将查找轮廓、XY和旋转

Hump Down AND LIGHT <<&书信电报;在这张图片中,我添加了局部照明,驼峰向下。其想法是对图像设置阈值并检测脊线,但由于局部照明是固定的,方向会影响到达脊线的光线,从而导致数据不一致

Hump Down with no light or back light <<&书信电报;这张照片是用我的手机拍摄的,没有背光。驼峰下降(参考图像)

Hump Up <<&书信电报;这是相同的,但驼峰向上,只有一个背光

Hump Up AND LIGHT <<&书信电报;驼峰是上背光和局部光

Hump Up with no light or back light <<&书信电报;驼峰向上(参考图像)


Tags: 对象图像lt分辨率局部电报cv2物体
1条回答
网友
1楼 · 发布于 2024-05-14 05:57:31

没有通用解决方案,但我想如果您进行Hough循环变换来检测循环位置并将其与图像的中间进行比较,您可能会有一个特殊的解决方案:

result

# Import Libraries
import numpy as np
import matplotlib.pyplot as plt

from skimage.io import imread
from skimage.color import rgb2gray, gray2rgb
from skimage.transform import hough_circle, hough_circle_peaks
from skimage.feature import canny
from skimage.draw import circle_perimeter

# Read image
img = imread('21.png')

# RGB to Gray
raw = rgb2gray(img)

# Edge detector
edges = canny(raw)

# Detect two radii
hough_radii = np.arange(5, 25, 2)
hough_res = hough_circle(edges, hough_radii)


# Select the most prominent 3 circles
accums, cx, cy, radii = hough_circle_peaks(hough_res, hough_radii,
                                           total_num_peaks=1)
# Check wither shape is up or down
if(cy > raw.shape[0]//2):
    pos = "shape is down"
else:
    pos = "shape is up"

# Draw them
fig, ax = plt.subplots(ncols=2, nrows=1, figsize=(10, 4))
image = gray2rgb(raw)
for center_y, center_x, radius in zip(cy, cx, radii):
    circy, circx = circle_perimeter(center_y, center_x, radius,
                                    shape=image.shape)
    image[circy, circx] = (220, 20, 20)

image[image.shape[0]//2,...] = (255,0,0)

ax[0].imshow(img)
ax[0].set_title('Original')
ax[0].axis('off')

ax[1].imshow(image)
ax[1].set_title(pos)
ax[1].axis('off')

plt.show()

相关问题 更多 >