您的位置:首页 > 编程语言

MeanShift代码-----应用中遇到的问题和解决+函数介绍

2011-01-15 12:13 441 查看
1、代码定义了byte类型

//define data types

typedef unsigned char byte;

即转换当成uchar转换即可

2、使用函数

主要的功能包括Filter和Segement,调用函数处理图像前需要定义图像数据,通过下面方法定义

msImageProcessor msIP;

msIP.DefineImage((byte*)img->imageData, COLOR, img->height, img->width);

//COLOR是ms中定义的一种类型:enum imageType {GRAYSCALE, COLOR};

//COLOR是彩色图像表示三通道,GRAYSCALE是灰度图像,一个通道

//定义之后即可进行其他处理

贴上我的主程序,以后弄丢了好找

// meanshift.cpp : Defines the entry point for the console application.

//

#include "stdafx.h"

#include "cv.h"

#include <tchar.h>

#include "highgui.h"

#include "Params.h"

#include "time.h"

#include "stdio.h"

#include <iostream>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])

{

int sigmaS = 6;

float sigmaR = 7;

int minRegion = 10;

//以上为三个参数----重要

char imgName[MAX_PATH] = {'/0'};

int count = 0;

//sprintf(imgName, "img-10.21op2-p-015t000-resized");

char add[MAX_PATH] = {'/0'};

//sprintf(imgadd, ".////data////images////%s.jpg", imgName);

FILE *trainList = fopen(".//data//evalList.txt", "r");

FILE *out;

int *labels_out;

float *modes_out;

int *MPC_out;

int regionCount = 0;

int h = 0, w = 0;

IplImage *img;

IplImage *rst;

//统计一下运行的时间

clock_t start, end;

while(fscanf(trainList, "%s", &imgName)!=EOF){

printf("%s...", imgName);

start = clock();

count++;

sprintf(add, ".////data////images////%s.jpg", imgName);

img = cvLoadImage(add);

rst = cvCloneImage(img);

regionCount = 0;

msImageProcessor msIP;

msIP.DefineImage((byte*)img->imageData, COLOR, img->height, img->width);

msIP.Segment(sigmaS, sigmaR, minRegion, HIGH_SPEEDUP);

regionCount = msIP.GetRegions(&labels_out, &modes_out, &MPC_out);

printf("regionCount = %d", regionCount);

msIP.GetResults((byte*)rst->imageData);

RegionList *rl = msIP.GetBoundaries();

//结果输出

//save labels_out

sprintf(add, ".////data////meanshift////%s.sp.txt", imgName);

out = fopen(add, "w");

for(h = 0; h<320; h++){

for(w = 0; w<240; w++){

fprintf(out, "%d ", labels_out[h*240+w]);

}

fprintf(out, "/n");

}

fclose(out);

//msIP.~msImageProcessor();

delete [] labels_out;

delete [] modes_out;

delete [] MPC_out;

cvReleaseImage(&img);

cvReleaseImage(&rst);

end = clock();

cout<<"Run time: "<<(double)(end - start) / CLOCKS_PER_SEC / 60<<"min ";

printf("done! No.%d/n", count);

}

system("PAUSE");

return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐