Ask Your Question
0

opencv imread, does it perform a deep copy?

asked 2013-12-13 16:08:35 -0600

kalyanramu gravatar image

updated 2018-12-12 14:34:20 -0600

Hi all,

I am new to OpenCV. I am using the following syntax in my code Mat image = imread(filename);

I wanted to understand how image is loaded into matrix and dug into source code of imread. Mat imread( const string& filename, int flags ) { Mat img; imread_( filename, flags, LOAD_MAT, &img ); return img; }

In this context, it seems that image from file is loaded into img, then to image.

Is the copy from img to image a shallow copy or deep copy? Any information in understanding details is greatly appreciated.

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
3

answered 2013-12-14 01:14:32 -0600

OpenCV cv::Mat class uses reference counting approach. So, both objects shares a single buffer with image without actual copying. If you need honest copy, call cv::Mat::copyTo method.

edit flag offensive delete link more
-1

answered 2013-12-14 01:40:11 -0600

amin.karimi gravatar image

hi i dont understand exactly what you say but i explain a bit about load image to program in additional code for add image to program you shoulad use

IplImage* img = cvLoadImage( "image.jpg" );

This line loads the image.* The function cvLoadImage()is a high-level routine that determines the file format to be loaded based on the fi le name; it also automatically allocates the memory needed for the image data structure. Note that cvLoadImage()can read a wide variety of image formats, including BMP, DIB, JPEG, JPE, PNG, PBM, PGM, PPM, SR, RAS, and TIFF. A pointer to an allocated image data structure is then returned. Th is structure, called IplImage, is the OpenCV construct with which you will deal the most.

but in c api at first you define a mat image that a image is like a mat after you read file from computer a depend to type of image like cv_8uc3 pixel to pixel of image(i.e inetensity if pixels) copy to mat and when u have 3 channels image indeed you have 3 mat or every location of mat has 3 value (intensity) at this state every image is mat finish ok ?

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-12-13 16:08:35 -0600

Seen: 1,075 times

Last updated: Dec 14 '13