Ask Your Question

make black image in opencv using Iplimage of user specified dimensions

asked 2013-10-28 08:55:05 -0500

zulfiqar gravatar image

updated 2013-10-28 09:31:49 -0500

I am new to opencv. I want to make a black image of user specified dimensions . I have found this

Mat atom_image = Mat::zeros( w, w, CV_8UC3 );

for Mat but i want to use IplImage * . Is there any method similar to the above for IplImage . Thanks for any help.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2013-10-28 09:23:44 -0500

updated 2013-10-28 10:15:27 -0500

My first reaction would be to ask why you would use the old C-style interface? If there is no specific reason, then please use the C++ interface, using Mat objects, which has a way larger support for the moment.

As to your problem, use the following commands

IplImage* img;
cvSet(img, cvScalar(0,0,0));

Which could be used for setting every possible value. However it can be done even more easily:

IplImage* img;
edit flag offensive delete link more


Its not working for me It gives error Error 3 error C2660: 'cvSetZero' : function does not take 2 arguments

zulfiqar gravatar imagezulfiqar ( 2013-10-28 10:01:22 -0500 )edit

Excuse me, to fast with copy paste. You should remove the second argument, since the function knows it needs to add a zero.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-10-28 10:16:25 -0500 )edit

May you tell us why do you prefer old, deprecated C-style interface?

stereomatching gravatar imagestereomatching ( 2013-10-28 11:17:28 -0500 )edit

in the second method how to specify the dimensions?

zulfiqar gravatar imagezulfiqar ( 2013-10-28 11:20:29 -0500 )edit

image = cvCreateImage(*size, IPL_DEPTH_8U, channels );

zulfiqar gravatar imagezulfiqar ( 2013-10-28 11:58:51 -0500 )edit

In the C API, you need to first define a pointer to memory with allocated space, by indeed using the cvCreateImage, which returns an IplImage pointer. Then you can use the provided functionality to add the values.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-10-29 04:26:44 -0500 )edit
Login/Signup to Answer

Question Tools


Asked: 2013-10-28 08:55:05 -0500

Seen: 2,788 times

Last updated: Oct 28 '13