Image processing 尺寸测量用摄像机图像校准-查找每像素毫米值
背景:我正试图用摄像机的视频信号实时测量物体的尺寸。我使用的是通用usb显微镜摄像头()。视频帧的分辨率为1280 x 720。我现在正在制作视频的单帧/图像 为了测量真实(物理)尺寸,我想首先校准摄像机测量值,即获得毫米/像素值。为了做到这一点,我用尺子代替了原来要测量的物体。由于相机是以一定角度安装的,为了获得自上而下或鸟瞰视图,我使用透视变换4点法对图像进行了校正 为了获得上面的透视校正图像,我创建了以下代码: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
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()
有什么原因不能沿标尺手动拾取两个像素并手动计算它们之间的像素数和毫米数?