#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <highgui.h>
#include<opencv2/imgproc/imgproc.hpp>
#include "cv.h"
using namespace cv;
using namespace std;
Mat g_cannyMat_output;
vector<vector<Point>> g_vContours;
vector<Vec4i> g_vHierarchy;
double minArea=30;
double maxArea=800;
double minLen=50;
double maxLen=200;
int slider_pos=70;//阈值
Mat dstImage,edge,grayImage,image0; //参数定义
void process_image(int h);
int main()
{
Mat srcImage=imread("filename.jpg");//载入原图像
cvNamedWindow("image");
imshow("image", srcImage); //显示图像
//【2】将原图像转换为灰度图像
cvtColor( srcImage, grayImage, COLOR_BGR2GRAY );
imshow("【效果图】灰度", grayImage);
//【3】先用使用 3x3内核来降噪
blur( grayImage, edge, Size(3,3) );
imshow("【效果图】模糊", edge);
//【4】运行Canny算子
Canny( edge, edge, 35, 115,3 );
//【5】显示效果图
imshow("【效果图】Canny边缘检测", edge); //将最高阈值为最低阈值的三倍
process_image(0);
waitKey(0);
}
void process_image(int h)
{
CvMemStorage *stor;
CvSeq *cont;
CvPoint *PointArray;
stor = cvCreateMemStorage(0);
cont = cvCreateSeq(CV_SEQ_ELTYPE_POINT,sizeof(CvSeq),sizeof(CvPoint),stor);
int count= cont->total;//轮廓个数
threshold(edge,dstImage,slider_pos,255,CV_THRESH_BINARY);
findContours( dstImage, g_vContours, g_vHierarchy, RETR_TREE, CHAIN_APPROX_SIMPLE, Point(0, 0) );
//cvFindContours(dstImage,stor,&cont,sizeof(CvContour),CV_RETR_LIST,CV_CHAIN_APPROX_NONE,cvPoint(0,0));
// 计算矩
vector<Moments> mu(g_vContours.size() );
for(unsigned int i = 0; i < g_vContours.size(); i++ )
{ mu[i] = moments( g_vContours[i], false ); }
// 计算中心矩
vector<Point2f> mc( g_vContours.size() );
for( unsigned int i = 0; i < g_vContours.size(); i++ )
{ mc[i] = Point2f( static_cast<float>(mu[i].m10/mu[i].m00), static_cast<float>(mu[i].m01/mu[i].m00 )); }
Mat drawing = Mat::zeros( dstImage.size(), CV_8UC3 );
//绘制轮廓并用椭圆拟合
for( unsigned int i = 0; i< g_vContours.size(); i++ )
{
double a = abs(contourArea(g_vContours[i]) ) ; //求轮廓面积
double b = abs(arcLength(g_vContours[i], true) ) ; //求轮廓长度
if( a>= minArea&&a<= maxArea&& b>= minLen&&b<= maxLen) //进行几何 束,面积阈值设置为1到800,长度阈值设置为5到 20
{
drawContours( drawing, g_vContours, i, Scalar(255,129,0), 2, 8, g_vHierarchy, 0, Point() );
//得到点集(这个方法值得借鉴)
//cvCvtSeqToArray(cont,PointArray,CV_WHOLE_SEQ);
////拟合当前轮廓
//fitEllipse(count);
//画椭圆
circle( drawing, mc[i], 4, Scalar(255,129,0), -1, 8, 0 );
}
/*ellipse(drawing,center,size,0,0,360,Scalar(255,129,0),1,8); */
}
imshow("Result",drawing);
}
没有合适的资源?快使用搜索试试~ 我知道了~
test9.zip_opencv 寻找mark_opencv 椭圆检测_opencv圆形 拟合_site:www.pudn.co
共83个文件
tlog:53个
pdb:4个
manifest:3个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 136 浏览量
2022-07-15
10:57:56
上传
评论
收藏 14.28MB ZIP 举报
温馨提示
OpenCV 的圆形标记点的提取方法, 通过对图像进行平滑处理 、 边缘检测 、 轮 廓查找 、 几何约束以及椭圆拟合, 实现圆形标记点的提取。 有关圆形物体识别的场合。
资源详情
资源评论
资源推荐
收起资源包目录
test9.zip (83个子文件)
test9
Release
test9.exe 10KB
test9.pdb 611KB
test9
Release
CL.write.1.tlog 218B
test9.log 2KB
CL.read.1.tlog 15KB
mt.read.1.tlog 552B
test9.exe.intermediate.manifest 381B
mt.command.1.tlog 368B
test9.write.1.tlog 0B
cl.command.1.tlog 586B
main.obj 1.01MB
link.write.1.tlog 334B
link.command.1.tlog 1KB
link.read.1.tlog 3KB
mt.write.1.tlog 192B
test9.lastbuildstate 43B
vc100.pdb 436KB
test9.vcxproj.user 143B
test9.vcxproj 4KB
test9.vcxproj.filters 942B
main.cpp 3KB
pic.jpg 65KB
filename.jpg 34KB
Debug
link.10716-cvtres.write.1.tlog 2B
test9.exe.embed.manifest 406B
vc100.idb 419KB
link.872-cvtres.write.1.tlog 2B
link.13488-cvtres.read.1.tlog 2B
link.5028-cvtres.read.1.tlog 2B
CL.write.1.tlog 210B
link.152-cvtres.read.1.tlog 2B
test9.log 3KB
CL.read.1.tlog 16KB
link.7468-cvtres.read.1.tlog 2B
mt.read.1.tlog 226B
rc.write.1.tlog 206B
link.152.write.1.tlog 2B
test9.exe.intermediate.manifest 381B
rc.read.1.tlog 198B
test9.exe.embed.manifest.res 472B
link.13488-cvtres.write.1.tlog 2B
link.872.write.1.tlog 2B
test9_manifest.rc 200B
link.5028-cvtres.write.1.tlog 2B
link.10828.read.1.tlog 2B
link.10828-cvtres.write.1.tlog 2B
mt.command.1.tlog 330B
test9.write.1.tlog 0B
cl.command.1.tlog 566B
link-cvtres.read.1.tlog 2B
link.13488.read.1.tlog 2B
main.obj 372KB
link.7468.write.1.tlog 2B
link.152-cvtres.write.1.tlog 2B
link.10828-cvtres.read.1.tlog 2B
link.5028.read.1.tlog 2B
link.write.1.tlog 490B
test9.vcxprojResolveAssemblyReference.cache 707B
link.872-cvtres.read.1.tlog 2B
link-cvtres.write.1.tlog 2B
link.command.1.tlog 1KB
rc.command.1.tlog 424B
link.read.1.tlog 3KB
link.13488.write.1.tlog 2B
link.872.read.1.tlog 2B
link.10716.write.1.tlog 2B
link.7468.read.1.tlog 2B
link.152.read.1.tlog 2B
mt.write.1.tlog 226B
link.5028.write.1.tlog 2B
test9.lastbuildstate 41B
link.10716.read.1.tlog 2B
link.10828.write.1.tlog 2B
link.7468-cvtres.write.1.tlog 2B
link.10716-cvtres.read.1.tlog 2B
vc100.pdb 524KB
test9.suo 24KB
test9.sln 882B
test9.sdf 12.71MB
ipch
test9-208866ce
test9-ab707e45.ipch 42.81MB
Debug
test9.ilk 2.65MB
test9.exe 106KB
test9.pdb 1.54MB
共 83 条
- 1
我虽横行却不霸道
- 粉丝: 72
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0