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

I have this same problem but I’m getting this error:

qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "/home/runner/MotionTracking/venv/lib/python3.8/site-packages/cv2/qt/plugins" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: xcb.

SIGABRT: abort
PC=0x7fc571a84baa m=0 sigcode=18446744073709551610
signal arrived during cgo execution

goroutine 1 [syscall, locked to thread]:
runtime.cgocall(0x4bb800, 0xc000066cd8)
    runtime/cgocall.go:156 +0x5c fp=0xc000066cb0 sp=0xc000066c78 pc=0x40651c
main._Cfunc_pry_eval_file(0x555557310c10, 0x55555733b930, 0x1, 0x5555573bf2b0)
    _cgo_gotypes.go:562 +0x4c fp=0xc000066cd8 sp=0xc000066cb0 pc=0x4b944c
main.Python.EvalFile.func5(0x5555573bf2b0, 0x8, {0xc000128170, 0x0, 0x40ced5}, 0x0)
    github.com/replit/prybar/languages/python3/main.go:92 +0x75 fp=0xc000066d28 sp=0xc000066cd8 pc=0x4ba455
main.Python.EvalFile({}, {0x7ffe279bed50, 0x7}, {0xc000128170, 0x0, 0x0})
    github.com/replit/prybar/languages/python3/main.go:92 +0x20c fp=0xc000066de0 sp=0xc000066d28 pc=0x4ba22c
main.(*Python).EvalFile(0x5d56d0, {0x7ffe279bed50, 0x5d56d0}, {0xc000128170, 0x0, 0xc000117040})
    <autogenerated>:1 +0x45 fp=0xc000066e18 sp=0xc000066de0 pc=0x4bb265
github.com/replit/prybar/utils.Language.EvalFile({{0x5075d0, 0x5d56d0}, {0x7ffe279bed3a, 0xc0001120f0}}, {0x7ffe279bed50, 0x7}, {0xc000128170, 0x0, 0x0})
    github.com/replit/prybar/utils/language.go:86 +0xa2 fp=0xc000066e78 sp=0xc000066e18 pc=0x4b8102
github.com/replit/prybar/utils.DoCli({0x5075d0, 0x5d56d0})
    github.com/replit/prybar/utils/utils.go:67 +0x2e8 fp=0xc000066f60 sp=0xc000066e78 pc=0x4b89a8
main.main()
    github.com/replit/prybar/languages/python3/generated_launch.go:7 +0x27 fp=0xc000066f80 sp=0xc000066f60 pc=0x4b8bc7
runtime.main()
    runtime/proc.go:255 +0x227 fp=0xc000066fe0 sp=0xc000066f80 pc=0x436d67
runtime.goexit()
    runtime/asm_amd64.s:1581 +0x1 fp=0xc000066fe8 sp=0xc000066fe0 pc=0x462e41

rax    0x0
rbx    0x6
rcx    0x7fc571a84baa
rdx    0x0
rdi    0x2
rsi    0x7ffe279bd130
rbp    0x7ffe279bd370
rsp    0x7ffe279bd1a8
r8     0x0
r9     0x7ffe279bd130
r10    0x8
r11    0x246
r12    0x555558101af8
r13    0x7ffe279bd540
r14    0x7ffe279bd4d8
r15    0x7ffe279bd548
rip    0x7fc571a84baa
rflags 0x246
cs     0x33
fs     0x0
gs     0x0
repl process died unexpectedly: exit status 2

My REPL