g++调用OpenCV

Linux

gcc/g++

Download OpenCV source codes (.tar.gz)

Root user

tar zxvf opencv-1.0.0.tar.gz; cd opencv-1.0.0
./configure
make
make install

General user

tar zxvf opencv-1.0.0.tar.gz; cd opencv-1.0.0
./configure --prefix=$HOME/usr
make
make install
# configuration
export PATH=$HOME/usr/bin/:$PATH
export LD_LIBRARY_PATH=$HOME/usr/lib:$LD_LIBRARY_PATH
export PKG_CONFIG_PATH=$HOME/usr/lib/pkgconfig:$PKG_CONFIG_PATH
export MANPATH=$HOME/usr/man:$MANPATH

Compilation is as

g++ `pkg-config --cflags opencv` foo.c -o foo `pkg-config --libs opencv`

It must be equivalent with

g++ -I$HOME/usr/include/opencv foo.c -o foo -L$HOME/usr/lib -lcxcore -lcv -lhighgui -lcvaux -lml

where $HOME/usr is the prefix specified at the ./configure step.

转自:http://note.sonots.com/OpenCV/Install.html#v6f9b80a

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以使用Matlab中的mex函数来调用OpenCV库中的函数,实现Matlab与OpenCV的交互。具体步骤如下: 1. 编写OpenCV C++代码实现需要的功能; 2. 将OpenCV C++代码编译成动态链接库(.dll或.so文件); 3. 在Matlab中编写mex函数,调用OpenCV动态链接库中的函数,实现功能。 以下是一个简单的例子,演示如何在Matlab中调用OpenCV库中的cv::resize函数: 1. 编写OpenCV C++代码: ```cpp #include <opencv2/opencv.hpp> using namespace cv; extern "C" void opencv_resize(double *input, int rows, int cols, double *output, int out_rows, int out_cols) { Mat input_mat(rows, cols, CV_64FC1, input); Mat output_mat(out_rows, out_cols, CV_64FC1, output); resize(input_mat, output_mat, output_mat.size()); } ``` 2. 将OpenCV C++代码编译成动态链接库。以Linux系统为例,编译命令为: ``` g++ -shared -o libopencv_resize.so opencv_resize.cpp `pkg-config --libs opencv` -fPIC ``` 3. 在Matlab中编写mex函数: ```matlab function output = opencv_resize(input, out_rows, out_cols) input = double(input); input_size = size(input); rows = input_size(1); cols = input_size(2); output = zeros(out_rows, out_cols); if ~libisloaded('libopencv_resize') loadlibrary('libopencv_resize.so', 'opencv_resize.h'); end calllib('libopencv_resize', 'opencv_resize', ... input, rows, cols, output, out_rows, out_cols); end ``` 4. 在Matlab中调用mex函数: ```matlab input = imread('input.jpg'); output = opencv_resize(input, 512, 512); imshow(uint8(output)); ``` 以上示例仅为演示如何在Matlab中调用OpenCV函数,实际使用时需要根据具体需求进行修改和完善。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值