Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Image processing 尺寸测量用摄像机图像校准-查找每像素毫米值_Image Processing_Camera Calibration_Opencv Python_Dimension_Perspectivecamera - Fatal编程技术网

Image processing 尺寸测量用摄像机图像校准-查找每像素毫米值

Image processing 尺寸测量用摄像机图像校准-查找每像素毫米值,image-processing,camera-calibration,opencv-python,dimension,perspectivecamera,Image Processing,Camera Calibration,Opencv Python,Dimension,Perspectivecamera,背景:我正试图用摄像机的视频信号实时测量物体的尺寸。我使用的是通用usb显微镜摄像头()。视频帧的分辨率为1280 x 720。我现在正在制作视频的单帧/图像 为了测量真实(物理)尺寸,我想首先校准摄像机测量值,即获得毫米/像素值。为了做到这一点,我用尺子代替了原来要测量的物体。由于相机是以一定角度安装的,为了获得自上而下或鸟瞰视图,我使用透视变换4点法对图像进行了校正 为了获得上面的透视校正图像,我创建了以下代码: import cv2 import numpy as np import

背景:我正试图用摄像机的视频信号实时测量物体的尺寸。我使用的是通用usb显微镜摄像头()。视频帧的分辨率为1280 x 720。我现在正在制作视频的单帧/图像

为了测量真实(物理)尺寸,我想首先校准摄像机测量值,即获得毫米/像素值。为了做到这一点,我用尺子代替了原来要测量的物体。由于相机是以一定角度安装的,为了获得自上而下或鸟瞰视图,我使用透视变换4点法对图像进行了校正

为了获得上面的透视校正图像,我创建了以下代码:

import cv2
import numpy as np
import matplotlib.pylot as plt

# To open matplotlib in interactive mode
%matplotlib qt5
 
# Load the image
img = cv2.imread('Extracted Images/Color/colorframe50.jpg') 

print('Width: {0}'.format(img.shape[1]))
print('Height: {0}'.format(img.shape[0]))
print('Channel: {0}'.format(img.shape[2]))
 
# Create a copy of the image
img_copy = np.copy(img)
 
# Convert to RGB so as to display via matplotlib
# Using Matplotlib we can easily find the coordinates of the 4 points that is essential for finding then transformation matrix
img = cv2.cvtColor(img,cv2.COLOR_BGR2RGB)
img_rgb = cv2.cvtColor(img_copy,cv2.COLOR_BGR2RGB)
 
#plt.imshow(img_copy)

scale_width = round(11.7348*100) # mm Actual ruler width measured using calipers
scale_height = round(6.35*100)   # mm Height based on selected 4 points for perspective transform 

# to calculate the transformation matrix
input_pts = np.float32([[192.30,343.00],[1079.0,379.80],[153.50,571.90],[1107.10,611.70]])
output_pts = np.float32([[0,0],[scale_width-1,0],[0,scale_height-1],[scale_width-1,scale_height-1]])

# Compute the perspective transform M
M = cv2.getPerspectiveTransform(input_pts,output_pts)
print(M.shape)
print(M)
 
# Apply the perspective transformation to the image
imgPersp = cv2.warpPerspective(img_rgb,M,(scale_width, scale_height)) #,flags=cv2.INTER_LINEAR)
imgGrayPersp = cv2.cvtColor(out, cv2.COLOR_BGR2GRAY)

# save image 
#cv2.imwrite('scalePerspCorrrected.jpg',imgGrayPersp)

# visulaize corners using cv2 circles
for x in range (0,4):
    cv2.circle(img_rgb,(input_pts[x][0],input_pts[x][1]),5,(255,0,0),cv2.FILLED)

# Plot results
plt.figure()    

titles = ['Original Image','4-point Selection','Perspective Warp Correction','Grayscale Perspective Warp Correction']
images = [img, img_rgb, imgPersp, imgGrayPersp]

for i in range(4):
    plt.subplot(2,2,i+1),plt.imshow(images[i],'gray') # use gray argument to correctly show grayscale images. Doesnt affect rgb images
    plt.title(titles[i])
    plt.xticks([]),plt.yticks([])

plt.show()
  • 选择透视变换的4个点时,我在matplotlib plot中使用鼠标指针观察x、y坐标。是否有一种精确的方法可以通过保持和边缘检测获得4个点?我想这会影响毫米/像素值

  • 我想测量标尺上刻度之间的像素数(例如,在上图中,标记8和右侧任何相邻刻度之间的像素数)。因为我已经知道标尺中刻度之间的实际距离,所以我可以得到每像素毫米的值。获取标尺上任意两个刻度之间距离的最佳操作顺序是什么?我该怎么办?有什么建议吗

  • 一旦我有了mm/像素值,我计划使用相同的4点和变换矩阵M变换包含待测量对象的图像,以获得未失真图像,并将mm/像素值与计算的对象距离(以像素为单位)相乘,以mm为单位找到真实尺寸

  • 我想测量对象的尺寸,公差至少为0.020 mm或更低。我试图测量的对象的典型尺寸在0.65到1.20毫米之间。要实现这一目标,我应该考虑哪些因素

  • 有什么原因不能沿标尺手动拾取两个像素并手动计算它们之间的像素数和毫米数?