Can’t figure out how to add a video to Python!

I can’t figure out why my code is not working it says something about config not being installed but I have installed almost every flipping package that has these stuff what have I done wrong in my code can anyone help me out?

Error message

My code yes this is from I cannot recall what website I got it from I have tried everything and it’s quite frustrating


import cv2

videoName = 'Test.mp4'

#create a videoCapture Object (this allow to read frames one by one)
video = cv2.VideoCapture(videoName)
#check it's ok
if video.isOpened():
    print('Video Succefully opened')
else:
    print('Something went wrong check if the video name and path is correct')


#define a scale lvl for visualization
scaleLevel = 3 #it means reduce the size to 2**(scaleLevel-1)


windowName = 'Video Reproducer'
cv2.namedWindow(windowName )
#let's reproduce the video
while True:
    ret,frame = video.read() #read a single frame 
    if not ret: #this mean it could not read the frame 
         print("Could not read the frame")   
         cv2.destroyWindow(windowName)
         break

    reescaled_frame  = frame
    for i in range(scaleLevel-1):
        reescaled_frame = cv2.pyrDown(reescaled_frame)

    cv2.imshow(windowName, reescaled_frame )

    waitKey = (cv2.waitKey(1) & 0xFF)
    if  waitKey == ord('q'): #if Q pressed you could do something else with other keypress
         print("closing video and exiting")
         cv2.destroyWindow(windowName)
         video.release()
         break

#release the video
video.release()

Can anyone help me?

Hi @BassetHoundDev. Thank you for your post.

In order for the community to suggest ideas to help you solve your code issue it would be useful to share a link to your Repl.

Thank you for posting the error message, that will definitely help!

1 Like

Hey, @BassetHoundDev!

You could use this code :

# importing libraries
import cv2
import numpy as np

# Create a VideoCapture object and read from input file
cap = cv2.VideoCapture('Spend Your Summer Vacations\
Wisely! Ft. Sandeep Sir _ GeeksforGeeks.mp4')

# Check if camera opened successfully
if (cap.isOpened()== False):
	print("Error opening video file")

# Read until video is completed
while(cap.isOpened()):
	
# Capture frame-by-frame
	ret, frame = cap.read()
	if ret == True:
	# Display the resulting frame
		cv2.imshow('Frame', frame)
		
	# Press Q on keyboard to exit
		if cv2.waitKey(25) & 0xFF == ord('q'):
			break

# Break the loop
	else:
		break

# When everything done, release
# the video capture object
cap.release()

# Closes all the frames
cv2.destroyAllWindows()

Sadly,that doesn’t work here is the error message that appears

Try after running in shell:

pip install --force-reinstall opencv-python&

And make sure the process isn’t interrupted

I was gonna ask about that how do you install stuff through the shell I still cant figure it out

depends on the “stuff”. For python packages, run in shell:

poetry add <package name>

For general nix packages, search using https://search.nixos.org, then install using:

sed -i "s/\];/    pkgs.<package name>  
  &/" replit.nix

Im sorry i sound annoying can you send a picture of how the shell would look if you installed open cv im really getting frustrated at this if you could this would help me a ton if i can see it thanks

Wdym that link doesn’t work

Is the video for Rick Rolling

No lol i was making a Easter egg of a show but if you want me to rick roll you i can ha ha

Did you try replit package manager to install?

Yes I tried many packages and still didn’t work