OpenCV capturing imagem with black side bars












3















I'm try to capture photos and videos using cv2.VideoCapture and cameras with ratio 16:9. But all image is returned by OpenCV with black side, cropping the image. In my example, instead of return an image with 1280 x 720, it return a 960 x 720 image. The same occurs using a webcam C920 (1920 x 1080).



What I´m doing wrong?



import cv2

video = cv2.VideoCapture(0)
video.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)
video.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)

while True:
conected, frame = video.read()
cv2.imshow("Video", frame)
if cv2.waitKey(1) == ord('s'):
video.release()
break

cv2.destroyAllWindows()


Using OpenCV:



Image with black sides



Using Windows Camera:



enter image description here










share|improve this question

























  • maybe you should upgrade OpenCV version to 3 latest

    – seokrae.kim
    Aug 28 '18 at 1:18











  • Im using OpenCV 3.4.2

    – MarceloSouza
    Aug 28 '18 at 9:51











  • Maybe your camera isn't capable of 1280x720, not all cameras shoot all resolutions.

    – Mark Setchell
    Aug 28 '18 at 10:40











  • When I use Sarxos library or use Windows Camera application, the image is shown correctly.

    – MarceloSouza
    Aug 28 '18 at 13:00











  • Just for fun, try setting the height first, then the width - I mean swap the order of the two lines setting the height and width.

    – Mark Setchell
    Aug 29 '18 at 12:48
















3















I'm try to capture photos and videos using cv2.VideoCapture and cameras with ratio 16:9. But all image is returned by OpenCV with black side, cropping the image. In my example, instead of return an image with 1280 x 720, it return a 960 x 720 image. The same occurs using a webcam C920 (1920 x 1080).



What I´m doing wrong?



import cv2

video = cv2.VideoCapture(0)
video.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)
video.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)

while True:
conected, frame = video.read()
cv2.imshow("Video", frame)
if cv2.waitKey(1) == ord('s'):
video.release()
break

cv2.destroyAllWindows()


Using OpenCV:



Image with black sides



Using Windows Camera:



enter image description here










share|improve this question

























  • maybe you should upgrade OpenCV version to 3 latest

    – seokrae.kim
    Aug 28 '18 at 1:18











  • Im using OpenCV 3.4.2

    – MarceloSouza
    Aug 28 '18 at 9:51











  • Maybe your camera isn't capable of 1280x720, not all cameras shoot all resolutions.

    – Mark Setchell
    Aug 28 '18 at 10:40











  • When I use Sarxos library or use Windows Camera application, the image is shown correctly.

    – MarceloSouza
    Aug 28 '18 at 13:00











  • Just for fun, try setting the height first, then the width - I mean swap the order of the two lines setting the height and width.

    – Mark Setchell
    Aug 29 '18 at 12:48














3












3








3








I'm try to capture photos and videos using cv2.VideoCapture and cameras with ratio 16:9. But all image is returned by OpenCV with black side, cropping the image. In my example, instead of return an image with 1280 x 720, it return a 960 x 720 image. The same occurs using a webcam C920 (1920 x 1080).



What I´m doing wrong?



import cv2

video = cv2.VideoCapture(0)
video.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)
video.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)

while True:
conected, frame = video.read()
cv2.imshow("Video", frame)
if cv2.waitKey(1) == ord('s'):
video.release()
break

cv2.destroyAllWindows()


Using OpenCV:



Image with black sides



Using Windows Camera:



enter image description here










share|improve this question
















I'm try to capture photos and videos using cv2.VideoCapture and cameras with ratio 16:9. But all image is returned by OpenCV with black side, cropping the image. In my example, instead of return an image with 1280 x 720, it return a 960 x 720 image. The same occurs using a webcam C920 (1920 x 1080).



What I´m doing wrong?



import cv2

video = cv2.VideoCapture(0)
video.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)
video.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)

while True:
conected, frame = video.read()
cv2.imshow("Video", frame)
if cv2.waitKey(1) == ord('s'):
video.release()
break

cv2.destroyAllWindows()


Using OpenCV:



Image with black sides



Using Windows Camera:



enter image description here







python opencv






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Aug 28 '18 at 13:06







MarceloSouza

















asked Aug 27 '18 at 16:44









MarceloSouzaMarceloSouza

15817




15817













  • maybe you should upgrade OpenCV version to 3 latest

    – seokrae.kim
    Aug 28 '18 at 1:18











  • Im using OpenCV 3.4.2

    – MarceloSouza
    Aug 28 '18 at 9:51











  • Maybe your camera isn't capable of 1280x720, not all cameras shoot all resolutions.

    – Mark Setchell
    Aug 28 '18 at 10:40











  • When I use Sarxos library or use Windows Camera application, the image is shown correctly.

    – MarceloSouza
    Aug 28 '18 at 13:00











  • Just for fun, try setting the height first, then the width - I mean swap the order of the two lines setting the height and width.

    – Mark Setchell
    Aug 29 '18 at 12:48



















  • maybe you should upgrade OpenCV version to 3 latest

    – seokrae.kim
    Aug 28 '18 at 1:18











  • Im using OpenCV 3.4.2

    – MarceloSouza
    Aug 28 '18 at 9:51











  • Maybe your camera isn't capable of 1280x720, not all cameras shoot all resolutions.

    – Mark Setchell
    Aug 28 '18 at 10:40











  • When I use Sarxos library or use Windows Camera application, the image is shown correctly.

    – MarceloSouza
    Aug 28 '18 at 13:00











  • Just for fun, try setting the height first, then the width - I mean swap the order of the two lines setting the height and width.

    – Mark Setchell
    Aug 29 '18 at 12:48

















maybe you should upgrade OpenCV version to 3 latest

– seokrae.kim
Aug 28 '18 at 1:18





maybe you should upgrade OpenCV version to 3 latest

– seokrae.kim
Aug 28 '18 at 1:18













Im using OpenCV 3.4.2

– MarceloSouza
Aug 28 '18 at 9:51





Im using OpenCV 3.4.2

– MarceloSouza
Aug 28 '18 at 9:51













Maybe your camera isn't capable of 1280x720, not all cameras shoot all resolutions.

– Mark Setchell
Aug 28 '18 at 10:40





Maybe your camera isn't capable of 1280x720, not all cameras shoot all resolutions.

– Mark Setchell
Aug 28 '18 at 10:40













When I use Sarxos library or use Windows Camera application, the image is shown correctly.

– MarceloSouza
Aug 28 '18 at 13:00





When I use Sarxos library or use Windows Camera application, the image is shown correctly.

– MarceloSouza
Aug 28 '18 at 13:00













Just for fun, try setting the height first, then the width - I mean swap the order of the two lines setting the height and width.

– Mark Setchell
Aug 29 '18 at 12:48





Just for fun, try setting the height first, then the width - I mean swap the order of the two lines setting the height and width.

– Mark Setchell
Aug 29 '18 at 12:48












3 Answers
3






active

oldest

votes


















1














I had the same issue too, but only on Windows 10, OpenCV 3.4 and Python 3.7.
I get the full resolution without the black side bars on a Mac OS.



I used PyGame to capture the webcam input and got the full resolution of 1920x1080 on Windows.






share|improve this answer































    0














    Just resize the received frame:



       cv::Mat dst;
    cv:resize(frame,dst,cv::Size(1280,720));
    cv::imshow("Video",dst);


    Check it!






    share|improve this answer
























    • That will just distort the image to fill the size, but it still won't capture the information in the wider field of view.

      – Mark Setchell
      Aug 29 '18 at 12:47











    • I tried it, but didn't work. Thank you

      – MarceloSouza
      Aug 29 '18 at 15:46



















    0














    I had this exact issue with a Logitech wide angle in windows camera and I was wondering about a driver problem.



    So I solved it using the DirectShow driver instead of the native driver using this:



    cv2.VideoCapture(cv2.CAP_DSHOW)


    If you have more than one camera add the index to that value like this



    cv2.VideoCapture(cv2.CAP_DSHOW + camera_index)


    It will accept the desired resolution by applying the right aspect ratio without having the sidebars.






    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',
      autoActivateHeartbeat: false,
      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%2f52043671%2fopencv-capturing-imagem-with-black-side-bars%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      I had the same issue too, but only on Windows 10, OpenCV 3.4 and Python 3.7.
      I get the full resolution without the black side bars on a Mac OS.



      I used PyGame to capture the webcam input and got the full resolution of 1920x1080 on Windows.






      share|improve this answer




























        1














        I had the same issue too, but only on Windows 10, OpenCV 3.4 and Python 3.7.
        I get the full resolution without the black side bars on a Mac OS.



        I used PyGame to capture the webcam input and got the full resolution of 1920x1080 on Windows.






        share|improve this answer


























          1












          1








          1







          I had the same issue too, but only on Windows 10, OpenCV 3.4 and Python 3.7.
          I get the full resolution without the black side bars on a Mac OS.



          I used PyGame to capture the webcam input and got the full resolution of 1920x1080 on Windows.






          share|improve this answer













          I had the same issue too, but only on Windows 10, OpenCV 3.4 and Python 3.7.
          I get the full resolution without the black side bars on a Mac OS.



          I used PyGame to capture the webcam input and got the full resolution of 1920x1080 on Windows.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Sep 24 '18 at 1:59









          kmocherlakmocherla

          211




          211

























              0














              Just resize the received frame:



                 cv::Mat dst;
              cv:resize(frame,dst,cv::Size(1280,720));
              cv::imshow("Video",dst);


              Check it!






              share|improve this answer
























              • That will just distort the image to fill the size, but it still won't capture the information in the wider field of view.

                – Mark Setchell
                Aug 29 '18 at 12:47











              • I tried it, but didn't work. Thank you

                – MarceloSouza
                Aug 29 '18 at 15:46
















              0














              Just resize the received frame:



                 cv::Mat dst;
              cv:resize(frame,dst,cv::Size(1280,720));
              cv::imshow("Video",dst);


              Check it!






              share|improve this answer
























              • That will just distort the image to fill the size, but it still won't capture the information in the wider field of view.

                – Mark Setchell
                Aug 29 '18 at 12:47











              • I tried it, but didn't work. Thank you

                – MarceloSouza
                Aug 29 '18 at 15:46














              0












              0








              0







              Just resize the received frame:



                 cv::Mat dst;
              cv:resize(frame,dst,cv::Size(1280,720));
              cv::imshow("Video",dst);


              Check it!






              share|improve this answer













              Just resize the received frame:



                 cv::Mat dst;
              cv:resize(frame,dst,cv::Size(1280,720));
              cv::imshow("Video",dst);


              Check it!







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Aug 29 '18 at 11:29









              Igor ZavistovichIgor Zavistovich

              173




              173













              • That will just distort the image to fill the size, but it still won't capture the information in the wider field of view.

                – Mark Setchell
                Aug 29 '18 at 12:47











              • I tried it, but didn't work. Thank you

                – MarceloSouza
                Aug 29 '18 at 15:46



















              • That will just distort the image to fill the size, but it still won't capture the information in the wider field of view.

                – Mark Setchell
                Aug 29 '18 at 12:47











              • I tried it, but didn't work. Thank you

                – MarceloSouza
                Aug 29 '18 at 15:46

















              That will just distort the image to fill the size, but it still won't capture the information in the wider field of view.

              – Mark Setchell
              Aug 29 '18 at 12:47





              That will just distort the image to fill the size, but it still won't capture the information in the wider field of view.

              – Mark Setchell
              Aug 29 '18 at 12:47













              I tried it, but didn't work. Thank you

              – MarceloSouza
              Aug 29 '18 at 15:46





              I tried it, but didn't work. Thank you

              – MarceloSouza
              Aug 29 '18 at 15:46











              0














              I had this exact issue with a Logitech wide angle in windows camera and I was wondering about a driver problem.



              So I solved it using the DirectShow driver instead of the native driver using this:



              cv2.VideoCapture(cv2.CAP_DSHOW)


              If you have more than one camera add the index to that value like this



              cv2.VideoCapture(cv2.CAP_DSHOW + camera_index)


              It will accept the desired resolution by applying the right aspect ratio without having the sidebars.






              share|improve this answer




























                0














                I had this exact issue with a Logitech wide angle in windows camera and I was wondering about a driver problem.



                So I solved it using the DirectShow driver instead of the native driver using this:



                cv2.VideoCapture(cv2.CAP_DSHOW)


                If you have more than one camera add the index to that value like this



                cv2.VideoCapture(cv2.CAP_DSHOW + camera_index)


                It will accept the desired resolution by applying the right aspect ratio without having the sidebars.






                share|improve this answer


























                  0












                  0








                  0







                  I had this exact issue with a Logitech wide angle in windows camera and I was wondering about a driver problem.



                  So I solved it using the DirectShow driver instead of the native driver using this:



                  cv2.VideoCapture(cv2.CAP_DSHOW)


                  If you have more than one camera add the index to that value like this



                  cv2.VideoCapture(cv2.CAP_DSHOW + camera_index)


                  It will accept the desired resolution by applying the right aspect ratio without having the sidebars.






                  share|improve this answer













                  I had this exact issue with a Logitech wide angle in windows camera and I was wondering about a driver problem.



                  So I solved it using the DirectShow driver instead of the native driver using this:



                  cv2.VideoCapture(cv2.CAP_DSHOW)


                  If you have more than one camera add the index to that value like this



                  cv2.VideoCapture(cv2.CAP_DSHOW + camera_index)


                  It will accept the desired resolution by applying the right aspect ratio without having the sidebars.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 21 '18 at 5:25









                  luismesasluismesas

                  12824




                  12824






























                      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.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52043671%2fopencv-capturing-imagem-with-black-side-bars%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







                      Popular posts from this blog

                      MongoDB - Not Authorized To Execute Command

                      in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

                      How to fix TextFormField cause rebuild widget in Flutter