您的程序是在opencv下实现边缘检测的吗?可以加你的QQ吗?我的814656461
展开全部
#include <cv.h>
#include <highgui.h>
#include <math.h>
#include <iostream.h>
#include <stdio.h>
int main(int argc, char** argv)
{
IplImage* img;
IplImage* temp=0;
if( argc == 2 && (img=cvLoadImage(argv[1],1))!= 0)
{
IplImage* gray = cvCreateImage( cvGetSize(img),8,1);
CvMemStorage* storage = cvCreateMemStorage(0);
CvSeq * pcontour=0; //提取轮廓的序列指针
cvCvtColor( img, gray, CV_BGR2GRAY); //转化为二值图像
cvThreshold(gray, gray,110,255,CV_THRESH_BINARY);//阈值化
cvSmooth(gray,gray,CV_MEDIAN,3,0,0,0);
cvErode(gray,gray,0,2); //侵蚀
cvDilate(gray,gray,0,1); //放大
cvNamedWindow( "circles1", 1 );
cvShowImage( "circles1", gray );
cvFindContours(gray,storage,&pcontour,sizeof(CvContour),CV_RETR_LIST,CV_LINK_RUNS,cvPoint(0,0));//查找轮廓
int n1=0;
for (;pcontour!=0;pcontour=pcontour->h_next)//画轮廓
{
CvRect r = ((CvContour*)pcontour)->rect;
int area=r.height * r.width;
if(area > 800&&area<6500)
{
cvRectangle(img,cvPoint(r.x,r.y),cvPoint(r.x + r.width, r.y + r.height),CV_RGB(0,0,255),1,CV_AA,0);
n1++;
//设定颜色
CvScalar color = CV_RGB(255,255,255);
//基于给定的矩形设置感兴趣区域ROI
cvSetImageROI(gray,r);
//填充
cvSet(gray,color);
//取消感兴趣区域
cvResetImageROI(gray);
}
}
cvNamedWindow( "circles3", 1 );
cvShowImage( "circles3", gray );
printf("%d",n1);
cvNamedWindow( "circles", 1 );
cvShowImage( "circles", img );
cvWaitKey(0);
cvReleaseImage(&img);
cvReleaseImage(&gray);
}
return 0;
}
#include <highgui.h>
#include <math.h>
#include <iostream.h>
#include <stdio.h>
int main(int argc, char** argv)
{
IplImage* img;
IplImage* temp=0;
if( argc == 2 && (img=cvLoadImage(argv[1],1))!= 0)
{
IplImage* gray = cvCreateImage( cvGetSize(img),8,1);
CvMemStorage* storage = cvCreateMemStorage(0);
CvSeq * pcontour=0; //提取轮廓的序列指针
cvCvtColor( img, gray, CV_BGR2GRAY); //转化为二值图像
cvThreshold(gray, gray,110,255,CV_THRESH_BINARY);//阈值化
cvSmooth(gray,gray,CV_MEDIAN,3,0,0,0);
cvErode(gray,gray,0,2); //侵蚀
cvDilate(gray,gray,0,1); //放大
cvNamedWindow( "circles1", 1 );
cvShowImage( "circles1", gray );
cvFindContours(gray,storage,&pcontour,sizeof(CvContour),CV_RETR_LIST,CV_LINK_RUNS,cvPoint(0,0));//查找轮廓
int n1=0;
for (;pcontour!=0;pcontour=pcontour->h_next)//画轮廓
{
CvRect r = ((CvContour*)pcontour)->rect;
int area=r.height * r.width;
if(area > 800&&area<6500)
{
cvRectangle(img,cvPoint(r.x,r.y),cvPoint(r.x + r.width, r.y + r.height),CV_RGB(0,0,255),1,CV_AA,0);
n1++;
//设定颜色
CvScalar color = CV_RGB(255,255,255);
//基于给定的矩形设置感兴趣区域ROI
cvSetImageROI(gray,r);
//填充
cvSet(gray,color);
//取消感兴趣区域
cvResetImageROI(gray);
}
}
cvNamedWindow( "circles3", 1 );
cvShowImage( "circles3", gray );
printf("%d",n1);
cvNamedWindow( "circles", 1 );
cvShowImage( "circles", img );
cvWaitKey(0);
cvReleaseImage(&img);
cvReleaseImage(&gray);
}
return 0;
}
东莞大凡
2024-08-07 广告
2024-08-07 广告
标定板认准大凡光学科技,专业生产研发厂家,专业从事光学影像测量仪,光学投影测量仪.光学三维测量仪,光学二维测量仪,光学二维测量仪,光学三维测量仪,光学二维测量仪.的研发生产销售。东莞市大凡光学科技有限公司创立于 2018 年,公司总部坐落于...
点击进入详情页
本回答由东莞大凡提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询