How to solve OverflowError: Python int too large to convert to C long with opencv? -


__author__ = 'kyle'  help_message = """script: frame_grabber.py usage: python frame_grabber.py path/to/video requires: opencv 2.4.8+ purpose: select , save frames given video.    commands:    key             function                  previous frame    d               next frame    q               exit    shift +       skip 10 frames forward    shift + d       skip 10 frames backwards    s               saves current frame    dbl click       saves current frame controls: slider          navigate through video """  # check if user has provided path file # otherwise display help_message  import sys import time t  # check if opencv module present # otherwise stop application  try:     import cv2 except importerror e:     print "fatal error: not import opencv, ", e    exit(-1) else:     print "using opencv ", cv2.__version__  # these flags may depend on opencv version: # in opencv 3.0.0 these flags implemented # cv2.cap_prop_pos_frames , # cv2.cap_prop_frame_count  current_frame_flag = cv2.cv.cv_cap_prop_pos_frames total_frames_flag = cv2.cv.cv_cap_prop_frame_count win_name = "frame grabber" pos_trackbar = "pos_trackbar"  #video_path = 'camera13.h264'    #try:   #   video_path = sys.argv[1]   # except indexerror e:   #   print help_message   #  exit(-1)       cap = cv2.videocapture("camera13.h264")      if not cap.isopened():         print "fatal error: not open specified file."         exit(-1)  ret, frame = cap.read()  if not ret:     print "fatal error: not read/decode frames specified file."     exit(-1)   def dummy():     pass   def save_image():     filename = "image_%0.5f.png" % t.time()     cv2.imwrite(filename, frame)   def seek_callback(x):     global frame     = cv2.gettrackbarpos(pos_trackbar, win_name)     cap.set(current_frame_flag, i-1)     _, frame = cap.read()     cv2.imshow(win_name, frame)   def mouse_callback(event,x,y,flags,param):  if event == cv2.event_lbuttondblclk:     save_image()    def skip_frame_generator(df):       def skip_frame():           global frame           cf = cap.get(current_frame_flag) - 1           cap.set(current_frame_flag, cf+df)           cv2.settrackbarpos(pos_trackbar, win_name,                  int(cap.get(current_frame_flag)))           _, frame = cap.read()  return skip_frame   cv2.namedwindow(win_name) cv2.createtrackbar(pos_trackbar, win_name, 0,             int(cap.get(total_frames_flag)), seek_callback) cv2.setmousecallback(win_name, mouse_callback)   actions = dict()  actions[ord("d")] = skip_frame_generator(10) actions[ord("d")] = skip_frame_generator(1) actions[ord("a")] = skip_frame_generator(-1) actions[ord("a")] = skip_frame_generator(-10) actions[ord("q")] = lambda: exit(0) actions[ord("s")] = save_image  while true:      cv2.imshow(win_name, frame)     key = cv2.waitkey(0) & 0xff     actions.get(key, dummy)()`` 

when code executed, receive error - overflowerror: python int large convert c long. how may go solving please? code meant create frame grabber allows me pick frame want , save it.

well, error telling you passing number in line:

cv2.createtrackbar(pos_trackbar, win_name, 0,int(cap.get(total_frames_flag)), seek_callback) 

that large cast ctypes.c_long; maximum number can represented type (2**31)-1 = 2147483647.

this presumably total_frames_flag. that's lot of frames (approx. 500 days @50fps), can't right.

i notice getting value before open video file, it's undefined @ point. try doing after you've opened file, , see if fixes things. print value, well, see if indeed large (before try suggested change).


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -