Python cv2, cant grab frame









up vote
-2
down vote

favorite












Im just starting to learn python. This is my first code. I tried using the webcam. For some reason it gives me an error.
Code



import cv2, time

video = cv2.VideoCapture(0)
check, frame = video.read()

print(check)
print(frame)

cv2.imshow("vegans have big gay", frame)

cv2.waitKey(0)
video.release()


errors:



False
[ WARN:0] videoio(MSMF): OnReadSample() is called with error status: -1072875772
None
[ WARN:0] videoio(MSMF): async ReadSample() call is failed with error status: -1072875772
[ WARN:1] videoio(MSMF): can't grab frame. Error: -1072875772
Traceback (most recent call last):
File "C:/Users/stasiek/PycharmProjects/pierwszy/capture.py", line 9, in <module>
cv2.imshow("vegans have big gay", frame)
cv2.error: OpenCV(3.4.3) C:projectsopencv-pythonopencvmoduleshighguisrcwindow.cpp:356: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'









share|improve this question

























    up vote
    -2
    down vote

    favorite












    Im just starting to learn python. This is my first code. I tried using the webcam. For some reason it gives me an error.
    Code



    import cv2, time

    video = cv2.VideoCapture(0)
    check, frame = video.read()

    print(check)
    print(frame)

    cv2.imshow("vegans have big gay", frame)

    cv2.waitKey(0)
    video.release()


    errors:



    False
    [ WARN:0] videoio(MSMF): OnReadSample() is called with error status: -1072875772
    None
    [ WARN:0] videoio(MSMF): async ReadSample() call is failed with error status: -1072875772
    [ WARN:1] videoio(MSMF): can't grab frame. Error: -1072875772
    Traceback (most recent call last):
    File "C:/Users/stasiek/PycharmProjects/pierwszy/capture.py", line 9, in <module>
    cv2.imshow("vegans have big gay", frame)
    cv2.error: OpenCV(3.4.3) C:projectsopencv-pythonopencvmoduleshighguisrcwindow.cpp:356: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'









    share|improve this question























      up vote
      -2
      down vote

      favorite









      up vote
      -2
      down vote

      favorite











      Im just starting to learn python. This is my first code. I tried using the webcam. For some reason it gives me an error.
      Code



      import cv2, time

      video = cv2.VideoCapture(0)
      check, frame = video.read()

      print(check)
      print(frame)

      cv2.imshow("vegans have big gay", frame)

      cv2.waitKey(0)
      video.release()


      errors:



      False
      [ WARN:0] videoio(MSMF): OnReadSample() is called with error status: -1072875772
      None
      [ WARN:0] videoio(MSMF): async ReadSample() call is failed with error status: -1072875772
      [ WARN:1] videoio(MSMF): can't grab frame. Error: -1072875772
      Traceback (most recent call last):
      File "C:/Users/stasiek/PycharmProjects/pierwszy/capture.py", line 9, in <module>
      cv2.imshow("vegans have big gay", frame)
      cv2.error: OpenCV(3.4.3) C:projectsopencv-pythonopencvmoduleshighguisrcwindow.cpp:356: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'









      share|improve this question













      Im just starting to learn python. This is my first code. I tried using the webcam. For some reason it gives me an error.
      Code



      import cv2, time

      video = cv2.VideoCapture(0)
      check, frame = video.read()

      print(check)
      print(frame)

      cv2.imshow("vegans have big gay", frame)

      cv2.waitKey(0)
      video.release()


      errors:



      False
      [ WARN:0] videoio(MSMF): OnReadSample() is called with error status: -1072875772
      None
      [ WARN:0] videoio(MSMF): async ReadSample() call is failed with error status: -1072875772
      [ WARN:1] videoio(MSMF): can't grab frame. Error: -1072875772
      Traceback (most recent call last):
      File "C:/Users/stasiek/PycharmProjects/pierwszy/capture.py", line 9, in <module>
      cv2.imshow("vegans have big gay", frame)
      cv2.error: OpenCV(3.4.3) C:projectsopencv-pythonopencvmoduleshighguisrcwindow.cpp:356: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'






      python frame webcam cv2






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 10 at 12:45









      stanisław słowiński

      15




      15






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          Try this way, resizing the video and wrapping video capture in a loop (with break on key pressed):



          import cv2

          video = cv2.VideoCapture(0)
          video.set(cv2.CAP_PROP_FRAME_WIDTH,640);
          video.set(cv2.CAP_PROP_FRAME_HEIGHT,480);

          while True:
          check, frame = video.read()
          cv2.imshow('Video window', frame)

          # press 'q' on keyboard to exit
          if cv2.waitKey(1) & 0xFF == ord('q'):
          break

          video.release()
          cv2.destroyAllWindows()





          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%2f53239091%2fpython-cv2-cant-grab-frame%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
            0
            down vote













            Try this way, resizing the video and wrapping video capture in a loop (with break on key pressed):



            import cv2

            video = cv2.VideoCapture(0)
            video.set(cv2.CAP_PROP_FRAME_WIDTH,640);
            video.set(cv2.CAP_PROP_FRAME_HEIGHT,480);

            while True:
            check, frame = video.read()
            cv2.imshow('Video window', frame)

            # press 'q' on keyboard to exit
            if cv2.waitKey(1) & 0xFF == ord('q'):
            break

            video.release()
            cv2.destroyAllWindows()





            share|improve this answer
























              up vote
              0
              down vote













              Try this way, resizing the video and wrapping video capture in a loop (with break on key pressed):



              import cv2

              video = cv2.VideoCapture(0)
              video.set(cv2.CAP_PROP_FRAME_WIDTH,640);
              video.set(cv2.CAP_PROP_FRAME_HEIGHT,480);

              while True:
              check, frame = video.read()
              cv2.imshow('Video window', frame)

              # press 'q' on keyboard to exit
              if cv2.waitKey(1) & 0xFF == ord('q'):
              break

              video.release()
              cv2.destroyAllWindows()





              share|improve this answer






















                up vote
                0
                down vote










                up vote
                0
                down vote









                Try this way, resizing the video and wrapping video capture in a loop (with break on key pressed):



                import cv2

                video = cv2.VideoCapture(0)
                video.set(cv2.CAP_PROP_FRAME_WIDTH,640);
                video.set(cv2.CAP_PROP_FRAME_HEIGHT,480);

                while True:
                check, frame = video.read()
                cv2.imshow('Video window', frame)

                # press 'q' on keyboard to exit
                if cv2.waitKey(1) & 0xFF == ord('q'):
                break

                video.release()
                cv2.destroyAllWindows()





                share|improve this answer












                Try this way, resizing the video and wrapping video capture in a loop (with break on key pressed):



                import cv2

                video = cv2.VideoCapture(0)
                video.set(cv2.CAP_PROP_FRAME_WIDTH,640);
                video.set(cv2.CAP_PROP_FRAME_HEIGHT,480);

                while True:
                check, frame = video.read()
                cv2.imshow('Video window', frame)

                # press 'q' on keyboard to exit
                if cv2.waitKey(1) & 0xFF == ord('q'):
                break

                video.release()
                cv2.destroyAllWindows()






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 10 at 14:47









                iGian

                2,2832620




                2,2832620



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53239091%2fpython-cv2-cant-grab-frame%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

                    Top Tejano songwriter Luis Silva dead of heart attack at 64

                    政党

                    天津地下鉄3号線