converting Mat to iplimage* in opencv

≯℡__Kan透↙ 提交于 2019-12-11 16:22:29

问题


I am new in opencv and c++. what is the difference between iplimage and iplimage*? I used cvHaarDetectObjects that need iplimage* in arg[1]. I have a frame in the format of Mat. how could I convert Mt to iplimage*? (I found a way to convert mat to iplimage but not to iplimage*).

the true one is :

iplimage* frame=cvLoadImage("1.jpg");
objects = cvHaarDetectObjects( frame, face_cascade, storage, scale_factor, 1 );

but I want to use:

Mat frame;
//some functions are performed on frame
objects = cvHaarDetectObjects( frame, face_cascade, storage, scale_factor, 1 );

回答1:


IplImage* is a pointer to the image data structure IplImage. It is used in C API of opencv.

After opencv 2.0, C++ API is introduced, and "Mat" structure replaced IplImage.

C API functions accept IplImage* instead of IplImage, and C++ API functions accept Mat.

Two solutions:

Mat frame;
// apply pre-processing functions
IplImage* frame2 = cvCloneImage(&(IplImage)frame);
objects = cvHaarDetectObjects(frame2, face_cascade, storage, scale_factor, 1 );

OR

use C++ API function accepting &frame, doing same job with haardetectobjects.




回答2:


If you already have the image in Mat format you should try this function call

void CascadeClassifier::detectMultiScale(const Mat& image, vector<Rect>& objects, double scaleFactor=1.1, int minNeighbors=3, int flags=0, Size minSize=Size(), Size maxSize=Size());

from the link in Canberk's answer

or try this

IplImage iplframe = IplImage( frame );
objects = cvHaarDetectObjects( &iplframe, face_cascade, storage, scale_factor, 1 );


来源:https://stackoverflow.com/questions/17379789/converting-mat-to-iplimage-in-opencv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!