otmane42
otmane42

Reputation: 643

How can I combine a transparent background image in png format with jpg images using opencv_createsamples?

I'm currently working on a project that consist of detecting a hand in a given image using OpenCV commands,and due to lack of positive images, I tried to create them artificially with the command opencv_createsamples, the background images (or negative images ) are in .jpg format, and my positive one is in .png format with a transparent background, the expected result should be something like: enter image description here

but what I got after running this command:

opencv_createsamples -img pos2/img.png -bg bg2.txt -info info/info.lst -pnginput info -maxxangle 0.5 -maxyangle 0.5 -maxzangle 0.5 -num 405 where :

  1. img.png contains a hand with a transparent background
  2. bg2.txt list of negative jpg images (or background )
  3. info is the folder where all the samples will be created
  4. info.lst is a file that contains the image path and the position(s) and number of the positive image(s) in each one

was:

as you can see, the positive image still have a white background, and there's no transparency as expected (the image is small because it's a 100x100 and the positive one is 50x50).

My question is, is there a way to get a result similar to the first image using the command opencv_createsamples?

Upvotes: 0

Views: 384

Answers (1)

sietschie
sietschie

Reputation: 7543

I quickly grepped through the source code of the function that is (I think) used:

https://github.com/opencv/opencv/blob/master/apps/createsamples/utility.cpp

What you can see there is that everytime imread is called the second parameter is IMREAD_GRAYSCALE. This means whatever the source image format is it will always be converted to grayscale. If there is an alpha channel present in the image it gets discarded.

So I think given this information it is not possible to get the result you want with this function.

Upvotes: 1

Related Questions