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;
}
//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;
}
相关文章推荐
- Tomcat调试ok的代码移植到Weblogic11g(server10.3.3),遇到的问题解决记录。
- 第一次上传代码到github中遇到的问题&解决方法
- Kettle 在应用中遇到的一些问题和解决方法
- [代码问题解决录]C#非模式窗体所遇到的问题与解决方案
- VC6.0代码向VS2005迁移遇到的问题与解决
- 360应用认领时遇到的问题时,我的解决方法.
- 代码批量生成WORD的遇到的问题及解决
- asp.net ajax应用中遇到的两个问题及解决方法
- 第一次上传代码到码云及遇到的一些问题和解决方式
- 开发Windows商店应用时使用SmsDevice类API遇到的Access Denied问题解决方法
- 《Thinking in Java》RMI远程方法示例代码运行是可能遇到的问题及解决方法
- 编译LDD第三版中scullc代码时遇到的问题及解决方法
- 如何解决GoAgent上传应用时遇到AttributeError: can't set attribute的问题
- linux kernel 编译内核模块代码,插入内核模块遇到的问题和解决
- [Windows通用应用开发] 代码编写StoryBoard时可能遇到的几个问题
- 基于51单片机的计算器写代码遇到的问题及解决办法
- ionic 代码在window上开发时在移动到苹果电脑上遇到的问题解决方法
- Struts+DAO的向oracle数据库插入数据的实现代码及遇到的问题(已解决)
- Eclipse开发Android应用时遇到的问题以及解决方法
- ProGuard总结和混淆Android代码中遇到的问题的解决方法以及寻找getSomething游戏