opencv 学习(一)

c 风格的写法和c++风格的写法

Mat imread imshow  是c++的风格,CvMat    IplImage  CvLoadimage CvRelease 是c风格的写法 ,另外c++的自动的管理内存,所以尽量用c++风格的写法吧

  

imread returns a Mat, not CvMat. They are the two different interfaces (Mat/imread for C++ and Ipl... and Cv.. for C interface). 

The C++ interface is nicer, safer and easier to use. It automatically handles memory for you, and allows you to write less code for the same task. The OpenCV guys advocate for the usage of C++, unless some very specific project requirements force you to C.

Example (C++)

cv::Mat image = imread("path/to/myimage.jpg")
if(image.empty())
    return;

cv::imshow("Image", image);

cv::Mat bw = image > 128; // threshold image
cv::Mat crop = image(cv::Rect(0, 0, 100, 100)); // a 100px x 100px crop
crop= 0; // set image to 0

cv::waitKey();
// end code here


And the C interface

IplImage* pImg = CvLoadImage("path/to/myimage.jpg");
if(pImg == NULL)
    return;

// ... big bloat to do the same operations with IplImage    

CvShowImage("Image", pImg);
cvWaitKey();
CvReleaseImage(&pImg); // Do not forget to release memory.
// end code here
一些等价

CvSize -> Size
CvVideoCapture -> VideoCapture
IplImage, CvMat -> Mat
cvQueryFrame -> >> (operator)
cvShowImage -> imshow
cvLoadImage -> imread


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值