我试图找到两个图像有多相似,但我遇到了分段错误。我做错了什么?
ExceptionInfo *exception;
Image *base_image, *reference_image, *composed_image, *image, *images, *images1;
double *similarity;
RectangleInfo offset;
ImageInfo *image_info, *image_info1;
char base_image_src[] = "jpgs/100000.jpg";
char reference_image_src[] = "jpgs/100000.jpg";
MagickCoreGenesis(NULL, MagickTrue);
exception = AcquireExceptionInfo();
image_info = CloneImageInfo((ImageInfo *) NULL);
(void) strcpy(image_info->filename, base_image_src);
base_image = ReadImage(image_info, exception);
image_info1 = CloneImageInfo((ImageInfo *) NULL);
(void) strcpy(image_info1->filename, reference_image_src);
reference_image = ReadImage(image_info1, exception);
offset.width = (unsigned int) 1200;
offset.height = (unsigned int) 1200;
offset.x = 0;
offset.y = 0;
composed_image = SimilarityImage(base_image, reference_image, &offset, similarity, exception);
编辑:我意识到它正在打破SimilarityImage。 来自/usr/lib64/libMagickCore.so.2的SimilarityImage()中的0x000000371dc5fdfa
答案 0 :(得分:0)
在这个例子中,我认为分段错误/总线错误与similarity
变量的双指针有关。与offset
一样,在堆栈中声明它,并传递它的引用。
// From
double *similarity;
// To
double similarity;
// And from
composed_image = SimilarityImage(base_image, reference_image, &offset, similarity, exception);
// To
composed_image = SimilarityImage(base_image, reference_image, &offset, &similarity, exception);
或分配双
double *similarity = (double *)malloc(sizeof(double));