Ask Your Question
0

make black image in opencv using Iplimage of user specified dimensions

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

zulfiqar gravatar image

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

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
3

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

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

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;
cvZero(img);
edit flag offensive delete link more

Comments

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 -0600 )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 -0600 )edit

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

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

in the second method how to specify the dimensions?

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

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

zulfiqar gravatar imagezulfiqar ( 2013-10-28 11:58:51 -0600 )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 -0600 )edit

Question Tools

Stats

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

Seen: 3,913 times

Last updated: Oct 28 '13