使用C ++ opencv在黑白图像中查找对象的中心点

编程入门 行业动态 更新时间:2024-10-28 06:31:17
本文介绍了使用C ++ opencv在黑白图像中查找对象的中心点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有下面的图片。我的目标是找到对象中心点的x,y值。我试过中,您可以在这里找到图像的中心:

///获取质量中心: vector< Point2f> mc(contours.size()); for(int i = 0; i< contours.size(); i ++) {mc [i] = Point2f(mu [i] .m10 / mu [i] .m00,mu [我] .m01 / mu [i] .m00); }

你可以找到你的图像中心:

#includeopencv2 \ openncv.hpp using namespace cv; int main() { Mat1b gray = imread(path_to_image,IMREAD_GRAYSCALE); 时刻mu =时刻(灰色,真实); 点中心; center.x = mu.m10 / mu.m00; center.y = mu.m01 / mu.m00; Mat3b res; cvtColor(gray,res,CV_GRAY2BGR); circle(res,center,2,Scalar(0,0,255)); imshow(结果,res); waitKey(); 返回0; }

结果图片是:

I have the image below. My aim is to find x,y values of the center point of the object. I tried Image moments but I couldn't find any x,y values. How can I do that?

The center point shoud be the red point or something close to it.

解决方案

In the link you posted, you can find the center of the image here:

/// Get the mass centers: vector<Point2f> mc( contours.size() ); for( int i = 0; i < contours.size(); i++ ) { mc[i] = Point2f( mu[i].m10/mu[i].m00 , mu[i].m01/mu[i].m00 ); }

You can find the center of your image like this:

#include "opencv2\opencv.hpp" using namespace cv; int main() { Mat1b gray = imread("path_to_image", IMREAD_GRAYSCALE); Moments mu = moments(gray, true); Point center; center.x = mu.m10 / mu.m00; center.y = mu.m01 / mu.m00; Mat3b res; cvtColor(gray, res, CV_GRAY2BGR); circle(res, center, 2, Scalar(0,0,255)); imshow("Result", res); waitKey(); return 0; }

The resulting image is:

更多推荐

使用C ++ opencv在黑白图像中查找对象的中心点

本文发布于:2023-06-08 21:22:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/589290.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中心点   黑白   图像   对象   opencv

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!