NameError: name 'cap' is not defined

asked 2019-03-15 04:03:11 -0600

jeevitha gravatar image

updated 2019-03-15 04:55:13 -0600

.

import cv2
import os
dir_path = '/home/ji/YouTubeClips'

for name in os.listdir(dir_path):

#count=count+1
video_id = name.split('.')[0]
cap = cv2.VideoCapture(0)
success,image = vidcap.read()
count = 0
success = True

total_frames = vidcap.get(1)
single_frame = '/home/jeevitha/2017611005/frame_single/image/'+video_id+'.jpg'
if not (os.path.isfile(single_frame) ): 

    video_file_path=os.path.join(dir_path, name)
    print(video_file_path)
    if (cap.isOpened()== False): 
          print("Error opening video stream or file")
    total = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))


    if success:
        cv2.imwrite(video_id+'.jpg',image) 
        vidcap.set(cv2.CAP_PROP_POS_MSEC,(count*65000))    # added this line 
    # save frame as JPEG file

to solve this issue

edit retag flag offensive close merge delete

Comments

problem: you copy / pasted snippets without any understanding of it

berak gravatar imageberak ( 2019-03-15 04:15:31 -0600 )edit
berak gravatar imageberak ( 2019-03-15 04:33:32 -0600 )edit

vidcap.set(cv2.CAP_PROP_POS_MSEC,(count*65000)) # added this line

try to find out, why this is wrong (or -- too late)

berak gravatar imageberak ( 2019-03-15 04:34:09 -0600 )edit

you need to open a cv.VideoCapture instance per file you want to read.

(and no, i won't write your program. you've done enough harm with copy / paste already. now it's time to understand, what you're doing ;)

berak gravatar imageberak ( 2019-03-15 04:40:31 -0600 )edit

65000 is a seconds value of frame in video

jeevitha gravatar imagejeevitha ( 2019-03-15 04:41:09 -0600 )edit

yea, but there's no vidcap, no cap and no success defined ever --you never even tried to understand, what you're doing

berak gravatar imageberak ( 2019-03-15 04:44:10 -0600 )edit

no use opening a webcam, when you want to use video files

please stop that blind copy / paste approach -- you'll get nowwhere like this

berak gravatar imageberak ( 2019-03-15 05:00:17 -0600 )edit