0

I recently installed opencv ans tried to run a simple process some of the commands won't read such as cv2.imshow() or cv2.imread () along with the waitkey() everything else works fine but a few necessary likes of code. Is it that i dont have have depencies for them or is it something else?

My code

import numpy as np
Import cv2

cap = cv2.VideoCapture(0)

while(True)
        #Capture frame-by-frame
        ret, frame = cap.read()
        out.write(frame)
        #Display the resulting frame
        cv2.imshow('frame', frame)
        if cv2.waitkey(20) & 0xFF == ord('q'):
              break

# When everything done, release the capture
cap.release()
out.write()
cv2.destroyAllWindows()```

Errors i get

Traceback  (most recent call last):
  File "/home/pi/test.py", line 9 in <module>
      out.write(frame)
NameError: 'out' is not defined

Cv2.imshow()
Cv2.error: OpenCV(3.4.4) /home/pi/packaging/opencv-python/opencv/modules/highgui/src/window.cpp:356: error: (-215: assertion failed) size.width>0 && size.height>0 in function 'imshow'```
Dirk
  • 3,541
  • 3
  • 18
  • 25
Entity
  • 11
  • 3
  • 2
    some of the commands won't read What exactly do you mean by that? Do you get an error message? Please add this information to your question. – Dirk Apr 02 '19 at 16:40
  • Theres out.read() and it sais that is isn't definined and for cv2.imread() it sais something about dimensions or coordinates i dont know but i cant really check to be sure because im in school and about to change classes – Entity Apr 02 '19 at 17:07
  • 1
    You don't have to do it now, but you really have to give more detailed information than just it sais something about dimensions or coordinates. Add some problem code and full error messages to your question – Dirk Apr 02 '19 at 18:04
  • NameError: 'out' is not defined Error says it: 'out' needs to be defined first. No idea what it's supposed to do. Did you copy this code from somewhere? Or adapted from an example? If so then please provide a link – Dirk Apr 04 '19 at 07:52
  • https://youtu.be/QjKmgdrNCP0 it was a test code – Entity Apr 04 '19 at 12:14
  • Sorry, I'm bailing out here. I don't do video tutorials. Seems to be a very long one too... – Dirk Apr 04 '19 at 13:16
  • Welcome to Stack Exchange @Entity. So far, the problem you've described seems to be more of a general programming issue rather than Raspberry Pi-specific. Please don't expect users to go through a whole tutorial to understand what you're trying to do; let alone a video tutorial. It is up to you to clearly describe your issue. – David Apr 05 '19 at 00:58
  • The error you're getting is 'out' is not defined. If you look at this example from another question you'll see that out is defined before being used. Something like this: out = cv2.VideoWriter('test_output.avi',fourcc, 20.0, (640,480),0) – David Apr 05 '19 at 00:59
  • Ok so now i just get the error for cv2.imshow('frame',frame) about assertion failure – Entity Apr 05 '19 at 15:34

0 Answers0