我正在尝试使用金字塔进行均值移位分段,如Learning OpenCV书中对某些图像所述。源图像和目标图像都是8位,三通道彩色图像,其宽度和高度与上述相同。 但是,仅在1600x1200或1024x768图像上获得正确的输出。尺寸为625x391和644x438的其他图像会导致运行时错误 “输入参数的大小在函数cvPyrUp()中不匹配” 我的代码是这样的:
IplImage *filtered = cvCreateImage(cvGetSize(img),img->depth,img->nChannels);
cvPyrMeanShiftFiltering( img, filtered, 20, 40, 1);
程序使用样本中给出的参数。我试过减少价值观,认为这是一个图像尺寸问题,但没有运气。 通过将图像尺寸调整为644x392和640x320,均值偏移正常运行。我读到“金字塔分割需要N次可被2整除的图像,其中N是要计算的金字塔图层的数量”,但这在哪里适用?
请提出任何建议。
答案 0 :(得分:1)
除了应用cvPyrMeanShiftFiltering之外,你还有其他任何东西 你应该这样做:
//A suggestion to avoid the runtime error
IplImage *filtered = cvCreateImage(cvGetSize(img),img->depth,img->nChannels);
cvCopy(img,filtered,NULL);
//Values only you should know
int level = kLevel;
int spatial_radius = kSpatial_Radius;
int color_radius = = kColor_Radius;
//Here comes the thing
filtered->width &= -(1<<level);
filtered->height &= -(1<<level);
//Now you are free to do your thing
cvPyrMeanSihftFiltering(filtered, filtered,spatial_radius,color_radius,level);
事实上,这种金字塔形过滤器根据您使用的级别修改了一些东西。试试这个,稍后告诉我是否有效。 希望我能提供帮助。