opencv在提取轮廓时,C/C++有两种方式,有些许不同,结合查找的资料和补充,做个小笔记;
功能,提取满足一定面积阈值和宽高比例的轮廓;
主函数
static int getContoursByC(char* Imgname, double minarea = 100, double whRatio = 1);
static int getContoursByCplus(char* Imgname, double minarea=0, double whRatio=1);
int main()
{
char* filename = new char[50];
strcpy(filename, "../image/rl_4.jpg");
getContoursByCplus(filename);
delete[] filename;
return 0;
}
API实现
cvFindContours形式
/*采用cvFindContours提取轮廓,并过滤掉小面积轮廓,最后将轮廓保存*/
static int getContoursByC(char* Imgname, double minarea, double whRatio)
{
IplImage* src = cvLoadImage(Imgname, CV_LOAD_IMAGE_GRAYSCALE);
if (!src)
{
printf("read data error!\n");
return -1;
}
IplImage* dst = cvCreateImage(cvGetSize(src), 8, 3);
//