Why am i get error like this : "Python stopped working"

83 Views Asked by At

When i try to run any python camera or web request project. I get an error like this"

When i try to run any python camera or web request project. I get an error like this

The translation is: "Python stopped working".

"A problem caused the program to stop working properly. Please close the program."

I think it being while import cv2 module. How can i solve this problem.

My code:

import cv2

kamera = cv2.VideoCapture(0)

ret, cerceve = kamera.read()
gri_cerceve = cv2.cvtColor(cerceve, cv2.COLOR_BGR2GRAY)

cv2.imshow('Kamera Uygulaması', gri_cerceve)

kamera.release()

cv2.destroyAllWindows()

Note : My computer is Windows 7 and 32 bit. Also my python version is 3.8.10

1

There are 1 best solutions below

2
toyota Supra On

Why am i get error like this : "Python stopped working"

That is not the way how you write VideoCapture.

Try this re-wrote the script:

snippet:

import numpy as np
import cv2

kamera = cv2.VideoCapture(0)

kamera.open(0)
print(kamera.isOpened())
while kamera.isOpened():
    # Capture frame-by-frame
    ret, frame = kamera.read()
    print(ret)
    print(frame)
         
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
     
    cv2.imshow('frame',gray)
    if cv2.waitKey(1) == ord('q'):
        break
     
kamera.release()
cv2.destroyAllWindows()

Screenshot:

enter image description here