我想知道这个程序的作用:
#include <iostream>
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
using namespace std;
int main(int argc, char* argv[])
{
printf("Hello world\n");
IplImage *img = cvLoadImage("C:/Program Files/OpenCV/samples/c/lena.jpg");
// Create a window
cvNamedWindow( "result",
CV_WINDOW_AUTOSIZE // allow window to resize to fit image true size
);
cvShowImage( "result", img ); // Show image in window already created
// Wait for a keystroke. If a positive argument is given, it will wait for
// that number of milliseconds and then continue. If 0 is given, the
// program will wait indefinitely for a keypress.
cvWaitKey(0);
// Clean up (not really necessary, but good programming practice)
cvReleaseImage( &img );
cvDestroyWindow("result");
system("PAUSE");
return EXIT_SUCCESS;
}
我问的原因是因为我认为在运行程序时应该弹出一张图片,但对我来说,会弹出一个灰色框。
有人可以对我的这个问题有所了解吗?提前谢谢。
答案 0 :(得分:1)
加载图片
显示图像
然后等待任何键(0)
在任意键上按
释放使用的内存并返回EXIT_SUCCESS
它应该正常工作,可能是路径不正确
尝试将图像复制到工作文件夹中,然后从中删除图像地址中的完整路径
“lena.jpg”
另一种选择是尝试反斜杠
“C:\\ Program Files \\ OpenCV \\ samples \\ c \\ lena.jpg”
编辑*
您应该运行openCV附带的诊断测试
它们位于opencv \ bin目录中,应该可以检查您的安装是否正确
答案 1 :(得分:0)
#include <stdio.h>
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
int main(int argc, char* argv[])
{
printf("Hello world\n");
IplImage *img = cvLoadImage("fruits.jpg",1);
// Create a window
cvNamedWindow( "result",
CV_WINDOW_AUTOSIZE // allow window to resize to fit image true size
);
cvShowImage( "result", img ); // Show image in window already created
// Wait for a keystroke. If a positive argument is given, it will wait for
// that number of milliseconds and then continue. If 0 is given, the
// program will wait indefinitely for a keypress.
cvWaitKey(0);
// Clean up (not really necessary, but good programming practice)
cvReleaseImage( &img );
cvDestroyWindow("result");
system("PAUSE");
return EXIT_SUCCESS;
}
Makefile(确保你有tab而不是8个空格!)
CFLAGS=-g -Wall
test = test
$(test): $(test).c
gcc -ggdb `pkg-config opencv --cflags --libs` -g -c -Wall $(test).c -o $(test).o
gcc -ggdb `pkg-config opencv --cflags --libs` -lpthread -lm $(test).o -o $(test)
clean:
@echo Removing generated files...
rm -f $(test).o $(test)
这个程序适合我!最好的问候,Virgoptrex!在Ubuntu 8.10上测试OpenCv 1.0!