Ask Your Question

convert mat to iplimage

asked 2012-10-08 09:57:00 -0500

andrea gravatar image

hi to all!

i have a simple question...can i convert a Mat imege into a Iplimage* ???

i need to insert the Mat image into a video,and the cvWriteFrema need a IplImage...

thanks :)

edit retag flag offensive close merge delete


Why don't you use VideoWriter::write?

Kirill Kornyakov gravatar imageKirill Kornyakov ( 2012-10-08 10:56:28 -0500 )edit

I try to use VideoWriter::write... I create

VideoWriter writer2("video_rect_out2.avi", CV_FOURCC('M','J','P','G'), fps, cvSize(img_template.cols, img_template.rows), true);

and after i use

writer2 << img_template;

but at the end the video result is empty...

andrea gravatar imageandrea ( 2012-10-08 11:37:36 -0500 )edit

2 answers

Sort by ยป oldest newest most voted

answered 2012-10-08 11:01:35 -0500

unxnut gravatar image
cv::Mat mat_img;
IplImage ipl_img = mat_img.operator IplImage();
edit flag offensive delete link more


Do you know how I could use this using Python?

creyesk gravatar imagecreyesk ( 2013-09-14 16:37:35 -0500 )edit

answered 2012-10-08 10:10:21 -0500

elmiguelao gravatar image

I have always had to do it myself in C:

void iplimage_from_cvmat(CvMat* input, IplImage * output)
  int x,y;
  for( x=0; x < output->width; x++ ){
    for( y=0; y < output->height; y++) {
      // note: CvMat is indexed (row, column) but IplImage is indexed (x,y)
      // so the indexes must be interchanged!
      cvSetReal2D( output, x, y, CV_MAT_ELEM(*input, uchar, y, x) );      
edit flag offensive delete link more


@elmiguelao: Can you provide the java equivalent of this code?

agile gravatar imageagile ( 2013-05-27 09:37:31 -0500 )edit

Question Tools


Asked: 2012-10-08 09:57:00 -0500

Seen: 10,888 times

Last updated: Oct 08 '12