编译opencv自带例子

如程序:/opencv/opencv-3.2.0/samples/cpp/tutorial_code/introduction/display_image/dispaly_image.cpp
<1>linux-x86版本:
命令:

g++ display_image.cpp -o display_image `pkg-config --cflags --libs opencv`


注意最右边的符号 ` 不是引号,而是键盘上 1 左边的那个。这是 shell 的语法,我就不多说了。
执行:./dispaly_image ./fish.jpg /**** 当前目录下有图片fish.ipg  ****/

g++ calibration.cpp -o calibration.o -c -Wall -I/usr/local/include/opencv -I/usr/local/include  
g++ calibration.o -o calibration -L/usr/local/lib -lopencv_shape -lopencv_stitching -lopencv_objdetect -lopencv_superres -lopencv_videostab -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_video -lopencv_photo -lopencv_ml -lopencv_imgproc -lopencv_flann -lopencv_core -lQtOpenGL -lQtGui -lQtTest -lQtCore -lpng -lz -ltiff -ljasper -ljpeg -lImath -lIlmImf -lIex -lHalf -lIlmThread -ldc1394 -lavcodec -lavformat -lavutil -lswscale -ldl -lm -lpthread -lrt -lGLU -lGL -lSM -lICE -lX11 -lXext -ltbb
 
  


<2>ARM(交叉编译)版本:
注:普通用户使用${CROSS_COMPILE}g++时,需要加载环境变量,一个窗口一次
1.到目录/usr/local/lib/pkgconfig
2.cp opencv.pc opencv_arm.pc 并修改第一行的路径为prefix=/usr/local/arm  (arm库所在路径);
3.把交叉编译好的arm版的lib和include全部复制的交叉编译工具对应的目录下:
如:
cp /usr/local/arm/lib/* /home/chen/my-imx6/03_tools/gcc-linaro-arm-linux-gnueabihf-4.9-2014.09_linux/arm-linux-gnueabihf/lib
cp /usr/local/arm/include/* /home/chen/my-imx6/03_tools/gcc-linaro-arm-linux-gnueabihf-4.9-2014.09_linux/arm-linux-gnueabihf/include -r    //复制目录记得加参数-r
${CROSS_COMPILE}g++ display_image.cpp -o display_image `pkg-config --cflags --libs opencv_arm` -lpthread -lrt -ldl
或:
sudo ${CROSS_COMPILE}g++ display_image.cpp -o display_image.o -c -Wall -I/usr/local/arm/include/opencv -I/usr/local/arm/include/opencv2
sudo ${CROSS_COMPILE}g++ display_image.o -o display_image -L/usr/local/arm/lib -lopencv_shape -lopencv_stitching -lopencv_objdetect -lopencv_superres -lopencv_videostab -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_video -lopencv_photo -lopencv_ml -lopencv_imgproc -lopencv_flann -lopencv_core -lQtOpenGL -lQtGui -lQtTest -lQtCore -lpng -lz -ltiff -ljasper -ljpeg -lImath -lIlmImf -lIex -lHalf -lIlmThread -ldc1394 -lavcodec -lavformat -lavutil -lswscale -ldl -lm -lpthread -lrt -lGLU -lGL -lSM -lICE -lX11 -lXext -ltbb

或:
绝对路径编译:
/home/chen/my-imx6/03_tools/gcc-linaro-arm-linux-gnueabihf-4.9-2014.09_linux/bin/arm-linux-gnueabihf-g++ capture.cpp -o arm_capture `pkg-config --cflags --libs opencv_arm` -lpthread -lrt -ldl
注意:由于使用pkg-config工具,系统会自动寻找调用的路径文件(如:opencv.pc),该文件在目录/usr/local/lib/pkgconfig
如果要编译arm版的,则需要复制opencv.pc文件为opencv_arm.pc并修改第一行的路径为prefix=/usr/local/arm  (arm库所在路径);

4.编译好的程序把整个文件夹复制到/home/下

你可能感兴趣的:(opencv,人工智能,计算机视觉)