/*
* cvPyrSegmentation用高斯图像金字塔做分割, 此函数还不支持直接画出contour,只能画出外接矩形
* 实验结果中分割的效果不佳
* Rocky Chen
* 2012/3/18
*/
#include "stdio.h"
#include "stdafx.h"
#include "highgui.h"
#include <cv.h>
#include <cxcore.h>
#include "iostream"
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
const char* win_original="original photo";
const char* win_PyrSegmentation = "PyrSegmentation";
const char* photo_file="E:\\iVew\\AB\\001.jpg"; //640*480 一定要检查图像是否能被2整除n次!!!!!
IplImage* img = cvLoadImage(photo_file);
assert(img != NULL); //有指针或内存分配要检查是否为空.表达式写完整,不能用assert(!img)代替
IplImage* img_dst = cvCreateImage(cvGetSize(img), img->depth,3);
assert(img_dst != NULL);
CvMemStorage* storage = cvCreateMemStorage(0); //分配存储区域
assert( storage !=NULL);
CvSeq* comp = NULL; //cvPyrSegmentation 需要用指向此指针的指针.
cvNamedWindow(win_original);
cvNamedWindow(win_PyrSegmentation);
cvPyrSegmentation(img, img_dst, storage, &comp, 4, 150, 30); // 图像的分辨率必须能被2整除n=4次
for (int i = comp->total -3; i < comp->total; i++)
{
CvConnectedComp* cc = (CvConnectedComp*) cvGetSeqElem(comp,i); //取序列
//画出block的外接矩形, cvPyrSegmentation还不支持直接画出contour, 分割的效果不佳
cvRectangle(img,
cvPoint(cc->rect.x,cc->rect.y),
cvPoint(cc->rect.x + cc->rect.width, cc->rect.y + cc->rect.height),
CV_RGB(255,0,0));
}
cvShowImage(win_original,img);
cvShowImage(win_PyrSegmentation, img_dst);
cvWaitKey();
cvReleaseMemStorage(&storage);
cvReleaseImage(&img);
cvReleaseImage(&img_dst);
cvDestroyAllWindows();
* cvPyrSegmentation用高斯图像金字塔做分割, 此函数还不支持直接画出contour,只能画出外接矩形
* 实验结果中分割的效果不佳
* Rocky Chen
* 2012/3/18
*/
#include "stdio.h"
#include "stdafx.h"
#include "highgui.h"
#include <cv.h>
#include <cxcore.h>
#include "iostream"
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
const char* win_original="original photo";
const char* win_PyrSegmentation = "PyrSegmentation";
const char* photo_file="E:\\iVew\\AB\\001.jpg"; //640*480 一定要检查图像是否能被2整除n次!!!!!
IplImage* img = cvLoadImage(photo_file);
assert(img != NULL); //有指针或内存分配要检查是否为空.表达式写完整,不能用assert(!img)代替
IplImage* img_dst = cvCreateImage(cvGetSize(img), img->depth,3);
assert(img_dst != NULL);
CvMemStorage* storage = cvCreateMemStorage(0); //分配存储区域
assert( storage !=NULL);
CvSeq* comp = NULL; //cvPyrSegmentation 需要用指向此指针的指针.
cvNamedWindow(win_original);
cvNamedWindow(win_PyrSegmentation);
cvPyrSegmentation(img, img_dst, storage, &comp, 4, 150, 30); // 图像的分辨率必须能被2整除n=4次
for (int i = comp->total -3; i < comp->total; i++)
{
CvConnectedComp* cc = (CvConnectedComp*) cvGetSeqElem(comp,i); //取序列
//画出block的外接矩形, cvPyrSegmentation还不支持直接画出contour, 分割的效果不佳
cvRectangle(img,
cvPoint(cc->rect.x,cc->rect.y),
cvPoint(cc->rect.x + cc->rect.width, cc->rect.y + cc->rect.height),
CV_RGB(255,0,0));
}
cvShowImage(win_original,img);
cvShowImage(win_PyrSegmentation, img_dst);
cvWaitKey();
cvReleaseMemStorage(&storage);
cvReleaseImage(&img);
cvReleaseImage(&img_dst);
cvDestroyAllWindows();
return 0;
}