用OpenCV计算到红点的距离
Calculate the distance to a red point with opencv
我是openCV的新手。刚刚设法安装并将其设置为Visual2013。我用笔记本电脑相机的实时流示例对其进行了测试。现在,我想通过网络摄像头与将位于屏幕中间的红色激光点(Live_stream)计算距离。告诉我从哪里开始?我知道我必须从屏幕中间找到R(红色)像素,但我不知道该怎么做以及可以使用什么功能。请问吗?来自网络摄像头的实时流如下所示:
#include "opencv2/highgui/highgui.hpp"
#include <opencv2/objdetect/objdetect.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
#include <vector>
#include <stdio.h>
int main()
{
//Data Structure to store cam.
CvCapture* cap=cvCreateCameraCapture(0);
//Image variable to store frame
IplImage* frame;
//Window to show livefeed
cvNamedWindow("Imagine Live",CV_WINDOW_AUTOSIZE);
while(1)
{
//Load the next frame
frame=cvQueryFrame(cap);
//If frame is not loaded break from the loop
if(!frame)
printf("nno");;
//Show the present frame
cvShowImage("Imagine Live",frame);
//Escape Sequence
char c=cvWaitKey(33);
//If the key pressed by user is Esc(ASCII is 27) then break out of the loop
if(c==27)
break;
}
//CleanUp
cvReleaseCapture(&cap);
cvDestroyAllWindows();
}
您的红点很可能会在相机流中显示为全白色,所以我建议
- 使用
cvtColor()
。
转换为灰度 - 使用
threshold()
的阈值,用于参数,使用阈值= 253,maxval = 255和mode thresh_binary。那应该给你一个全黑的图像,带有激光器所在的小白点。 - 然后,您可以使用
findContours()
在图像中找到点。获取轮廓的boundingRect()
,然后您可以计算其中心以获取点的精确坐标。
也已经提到,请勿使用弃用的C API,而是使用C API。
相关文章:
- 在 OpenCV 中计算 SURF 功能之间的距离
- 查找从轮廓到点OPENCV C 的距离
- 获取具有X,Y和距离的OPENCV中的3D坐标
- openCV的EMD-L1算法计算的距离为零
- 在opencv中,使用垫子类型计算马氏距离太慢了。如何提高效率?
- 如何在OpENCV中的图像中找到像素之间的欧几里得距离
- 用OpenCV计算到红点的距离
- OpenCV锤击匹配之间的距离距离
- OpenCV Mahalanobis函数,用于计算两个图像之间的距离
- 使用 OpenCV 和 OpenNI 测量 2 点之间的距离
- OpenCV查找近距离物体的轮廓
- OpenCV距离变换中的像素索引
- 使用OpenCV的Kmeans聚类中的mahalanobis距离
- 在OpenCV的距离变换方法上使用CV_DIST_USER时如何设置距离变换公式?
- Opencv DMatch距离超出范围
- OpenCV三角形点变化距离
- 在opencv中找到轮廓/物体之间的距离
- 物体到相机的距离,使用opencv
- 如何在OpenCV中计算两个gmm之间的距离
- 我需要一个例子,使用OpenCV 2面(UIimage)之间进行比较,并获得与IOS的距离