这是我想要实现对象测量的代码,但我不知道我将使用什么功能以及如何对其进行编码以及如何使其自动生成。有人可以帮助我吗?先谢谢你。
cv::VideoCapture cap;
if (!cap.isOpened()) // check if succeeded to connect to the camera
CV_Assert("Can't open Web-Cam");
double CamHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT);
double CamWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH);
//Display text on the screen function
int imgW = 650;
int imgH = 50;
int fontFace = FONT_HERSHEY_PLAIN;
double fontScale = 1.5;
int thickness = 2;
Point textOrg(imgW/5, imgH/1.3);
int value=10;
string someText = format("Dimension: %d ", value); //Display the dimension (output)
putText(frame, someText, textOrg, fontFace, fontScale, Scalar::all(255), thickness, 8);
imshow("Object Measurement",frame);;
答案 0 :(得分:1)
此代码是关于将文本放到某个图像上的。
您在哪里初始化frame
?
获取帧的主循环在哪里?
通常,您使用while(waitKey(someMiliseconds) != someValue)
来破坏获取帧并使用键盘按钮处理帧的循环。如果您不使用waitKey
,则会立即关闭窗口。
关于对象测量,对于逐像素测量,您需要使用findContours
,boundingRect
等方法。教程在this link上。对于真实世界的维度,您需要calibrate your camera,使用内在(焦距,扭曲)和外在(对象的深度)参数来重建真实世界坐标。通过深度信息,您可以提取实际尺寸(反之亦然)。
简而言之,除非假设物体的深度不变,否则不能仅使用一台相机“自动生成”3D重建和测量。 O.w.,用户应输入深度。
您可以utilize another camera使用立体视觉“自动生成”。