我寫了應該創建一個獨特的外觀梯度並將其保存到用戶指定一個文件下面的代碼示例:OpenCV的代碼示例錯誤
#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 1797 terminate 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 cvPtr2D Aborted (core dumped)
任何幫助,請?提前致謝! :)
不管怎麼說,而不是使用這種間接的訪問,我建議你使用C++包裝(見http://www.cs.iit.edu/~agam嘗試直接訪問/cs512/lect-notes/opencv-intro/opencv-intro.html#SECTION00053000000000000000)。您的代碼將更加高效和易於理解。 :) – zkan
你意味着什麼?順便說一下,這正是我用作參考的網站!大聲笑 – someone