combine a transparent background image in png format with jpg images using opencv_createsamples











up vote
0
down vote

favorite












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 ?



thanks for your help










share|improve this question




























    up vote
    0
    down vote

    favorite












    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 ?



    thanks for your help










    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      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 ?



      thanks for your help










      share|improve this question















      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 ?



      thanks for your help







      opencv png image-recognition






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 9 at 13:03

























      asked Nov 9 at 10:49









      otmane42

      185




      185
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote













          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.






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53224262%2fcombine-a-transparent-background-image-in-png-format-with-jpg-images-using-openc%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            1
            down vote













            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.






            share|improve this answer

























              up vote
              1
              down vote













              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.






              share|improve this answer























                up vote
                1
                down vote










                up vote
                1
                down vote









                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.






                share|improve this answer












                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.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 9 at 13:29









                sietschie

                5,19322446




                5,19322446






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53224262%2fcombine-a-transparent-background-image-in-png-format-with-jpg-images-using-openc%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    這個網誌中的熱門文章

                    Hercules Kyvelos

                    Tangent Lines Diagram Along Smooth Curve

                    Yusuf al-Mu'taman ibn Hud