linux centos 安装opencv

时间:2023-03-08 20:11:01

系统:Centos 6.5 
最后版本 OpenCV: 2.4.9

1、安装依赖包(很重要) 
yum install cmake gcc gcc-c++ gtk+-devel gimp-devel gimp-devel-tools gimp-help-browser zlib-devel libtiff-devel libjpeg-devel libpng-devel gstreamer-devel libavc1394-devel libraw1394-devel libdc1394-devel jasper-devel jasper-utils swig python libtool nasm

2.安装/更新CMake

yum install cmake      直接从网上安装cmake

3、安装Opencv 
cmake CMakeLists.txt

make  
make install

成功

4.编译

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

5.makefile编写

###########################################
#Makefile for simple programs
###########################################
INC=-I./include/ -I/usr/local/include -I/usr/local/include/opencv -I/usr/local/include/opencv2
LIB=-L/usr/local/lib/ -lopencv_core -lopencv_highgui -lpthread -lrt CC=g++
CC_FLAG=-Wall -g PRG=run
OBJ=main.o imagerecog.o ocr.o
CC_FLAG+=`pkg-config --cflags opencv`
LDFLAGS=`pkg-config --libs opencv` $(PRG):$(OBJ)
$(CC) $(INC) $(LIB) -o $@ $(OBJ) $(LDFLAGS) .SUFFIXES: .c .o .cpp
.cpp.o:
$(CC) $(CC_FLAG) $(INC) -c $*.cpp -o $*.o .PRONY:clean
clean:
@echo "Removing linked and compiled files......"
rm -f $(OBJ) $(PRG)