I have created a django web app and written code to get video feed from my laptop camera using opencv.
def start(request):
print("HI")
def testDevice():
cap = cv2.VideoCapture(0)
if cap is None or not cap.isOpened():
print('Warning: unable to open video source: ', source)
testDevice(0) # no printout
testDevice(1) # prints message
global video_thread
if video_thread is None or not video_thread.is_alive():
stop_event.clear()
video_thread = threading.Thread(target=run_video_feed)
video_thread.start()
return HttpResponse("Video feed started successfully.")
else:
return HttpResponse("Video feed is already running.")
The above code is fetching video feed while running in localhost. But when I uploaded(hosted) it in the pythonanywhere, it is not fetching the video feed and it prints Warning: unable to open video source.