Ask Your Question
0

convert mat to iplimage

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

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

Comments

Why don't you use VideoWriter::write?

Kirill Kornyakov gravatar imageKirill Kornyakov ( 2012-10-08 10:56:28 -0600 )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 -0600 )edit

2 answers

Sort by ยป oldest newest most voted
1

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

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

Comments

Do you know how I could use this using Python?

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

answered 2012-10-08 10:10:21 -0600

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

Comments

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

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

Question Tools

Stats

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

Seen: 12,453 times

Last updated: Oct 08 '12