vardanagarwal / Proctoring-AI

Creating a software for automatic monitoring in online proctoring
MIT License
540 stars 329 forks source link

AttributeError: 'NoneType' object has no attribute 'copy' for eye_tracker.py #41

Closed rudrarajurahul closed 3 years ago

rudrarajurahul commented 3 years ago

Hey. I am having trouble running eye_tracker.py file. It is unable to grab the frame.

[ WARN:0] global C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-kh7iq4w7\opencv\modules\videoio\src\cap_msmf.cpp (912) CvCapture_MSMF::grabFrame videoio(MSMF): can't grab frame. Error: -2147483638 Traceback (most recent call last): File "D:/Projects/exam_proctoring_model/Proctoring-AI-master/eye_tracker.py", line 160, in thresh = img.copy() AttributeError: 'NoneType' object has no attribute 'copy'

vardanagarwal commented 3 years ago

Could you try this: cap = cv2.VideoCapture(cv2.CAP_DSHOW)

rudrarajurahul commented 3 years ago

cap = cv2.VideoCapture(cv2.CAP_DSHOW) avoided the error. But I was just seeing a noisy flutter screen. Looks like its an issue with the systems webcam. When I tried to run a simple script to see if the code was able to access the webcam using

Code

import cv2

cap = cv2.VideoCapture(0)

cap = cv2.VideoCapture(cv2.CAP_DSHOW)

Check if the webcam is opened correctly

if not cap.isOpened(): raise IOError("Cannot open webcam")

while True: ret, frame = cap.read() frame = cv2.resize(frame, None, fx=0.5, fy=0.5, interpolation=cv2.INTER_AREA) cv2.imshow('Input', frame)

c = cv2.waitKey(1)
if c == 27:
    break

cap.release() cv2.destroyAllWindows()

This is the error its returning.

[ WARN:0] global C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-kh7iq4w7\opencv\modules\videoio\src\cap_msmf.cpp (912) CvCapture_MSMF::grabFrame videoio(MSMF): can't grab frame. Error: -2147483638 Traceback (most recent call last): File "D:/Projects/exam_proctoring_model/Proctoring-AI-master/webcam_testing.py", line 12, in frame = cv2.resize(frame, None, fx=0.5, fy=0.5, interpolation=cv2.INTER_AREA) cv2.error: OpenCV(4.5.1) C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-kh7iq4w7\opencv\modules\imgproc\src\resize.cpp:4051: error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize'

[ WARN:1] global C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-kh7iq4w7\opencv\modules\videoio\src\cap_msmf.cpp (434) `anonymous-namespace'::SourceReaderCB::~SourceReaderCB terminating async callback

Is there a specific opencv version that needs to be installed ?

vardanagarwal commented 3 years ago

The problem seems to be with the webcam itself. Can you try and use a saved video file? Just replace the 0 in cv2.VideoCapture with the file name in quotes.

The problem shouldn't be with the OpenCv vesion but if you want to have a shot in the dark you can try with Opencv 4.4

rudrarajurahul commented 3 years ago

Ya the problem is with the system. I have kaspersky antivirus installed with is blocking the webcam to be accessed.

vardanagarwal commented 3 years ago

Right!

rudrarajurahul commented 3 years ago

Appreciate your quick response. Thank You.