【发布时间】:2019-11-26 06:10:30
【问题描述】:
我在 opencv-python 中编写了一个代码,用于计算对象高度和宽度的像素数。 可以说,
高度 = 567 像素 宽度 = 324 像素 我还有 KNOWN_FOCAL_LENGTH 的相机和 原始物体和相机之间的距离。
# Getting the biggest contour
cnt = max(contours, key = cv2.contourArea)
cv2.drawContours(image, cnt, -1, (0, 255, 0), 3)
peri = cv2.arcLength(cnt, True)
approx = cv2.approxPolyDP(cnt, 0.005* peri, True)
# get the bounding rect
x, y, w, h = cv2.boundingRect(approx)
print("Width in pixels : {}, Height in pixels : {}".format(w,h))
# draw a green rectangle to visualize the bounding rect
cv2.rectangle(image, (x, y), (x+w, y+h), (0, 255, 0), 2)
WidthData = "Width : {} mm".format(round(w/scaling_factor,2))
HeightData = "Height : {} mm".format(round(h/scaling_factor,2))
textData = WidthData + ", " + HeightData
cv2.putText(image, textData, (x, y - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 0), 2)
print(WidthData)
print(HeightData)
cv2.imshow('Result', image)
如何计算可以将 number_of_pixels 转换为 original_length of 图片 ? 如何计算scaling_factor?
【问题讨论】:
标签: opencv camera-calibration object-recognition