我正在尝试使用金字塔运行均值偏移分割,如 Learning OpenCV 中所述预订一些图像。源图像和目标图像都是 8 位、三 channel 彩色图像,宽度和高度与上述图像相同。 然而,只有在 1600x1200 或 1024x768 图像上才能获得正确的输出。其他尺寸为 625x391 和 644x438 的图像导致运行时错误 “输入参数的大小在函数 cvPyrUp() 中不匹配” 我的代码是这样的:
IplImage *filtered = cvCreateImage(cvGetSize(img),img->depth,img->nChannels);
cvPyrMeanShiftFiltering( img, filtered, 20, 40, 1);
程序使用示例中给出的参数。我试过降低值,认为这是图像尺寸问题,但没有成功。 通过将图像尺寸调整为 644x392 和 640x320,均值漂移正常运行。我读过“金字塔分割需要被 2 整除 N 次的图像,其中 N 是要计算的金字塔层数”,但这在此处如何适用?
请提出任何建议。
最佳答案
好吧,除了当你应用 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);
问题是这种金字塔形过滤器会根据您使用的级别修改一些东西。试试这个,如果有效,稍后告诉我。 希望我能帮上忙。
关于visual-c++ - 金字塔中的错误意味着某些尺寸图像的平移过滤?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5391167/