gpt4 book ai didi

c - OpenCV 代码示例错误

转载 作者:太空宇宙 更新时间:2023-11-04 06:03:41 26 4
gpt4 key购买 nike

我编写了以下代码示例,它应该创建一个外观奇特的渐变并将其保存到用户指定的文件中:

#include <stdio.h>
#include <cv.h>
#include <highgui.h>

static IplImage *image = 0;

void main() {
char path[1024];
int x, y;
CvScalar scalar;

scanf("%s", path);
image = cvCreateImage(cvSize(640,480),IPL_DEPTH_8U,1);

for (y = 0; y < 480; y++) {
for (x = 0; x < 640; x++) {
scalar = cvGet2D(image, x, y);
scalar.val[0]=(unsigned char)(x + y);
cvSet2D(image, x, y, scalar);
}
}

cvSaveImage(path, image, 0);
}

我编译它使用:gcc opencv.c -o opencv `pkg-config --libs --cflags opencv` -lm 一切似乎都正常。但是,在运行时(输入:“sample.png”),出现以下错误:

OpenCV Error: One of arguments' values is out of range (index is out of range) in cvPtr2D, file /builddir/build/BUILD/OpenCV-2.3.1/modules/core/src/array.cpp, line 1797terminate called after throwing an instance of 'cv::Exception'  what():  /builddir/build/BUILD/OpenCV-2.3.1/modules/core/src/array.cpp:1797: error: (-211) index is out of range in function cvPtr2DAborted (core dumped)

有什么帮助吗?提前致谢! :)

最佳答案

cvGet2D 和 cvSet2D 像 opencv 中的许多其他函数一样使用 [行,列] 约定。

进一步阅读: http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/

关于c - OpenCV 代码示例错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14677660/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com