Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

VideoCapture so slow in reading video file.

Why is it if i read a video file using cv2.VideoCapture('video.avi') the fps is very very very low? I want the fps to be the same as when i play the video using a video player(30fps). What changes should i make to achieve this? Btw, i am using a raspberry pi 3 with python. import cv2 import numpy as np

cap = cv2.VideoCapture('Fchecking.avi')
kernel = np.ones((5,5), np.uint8)

while(1):

    # Take each frame
    ret, frame = cap.read()
    img2gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

   ret,mask = cv2.threshold(img2gray,140,255,cv2.THRESH_BINARY) 
    w3w = cv2.adaptiveThreshold(mask,255,cv2.ADAPTIVE_THRESH_MEAN_C,cv2.THRESH_BINARY,47,2)   
cv2.imshow("mask", mask)

mask_inv = cv2.bitwise_not(w3w) 

img2_fg = cv2.bitwise_and(frame, frame, mask=mask_inv)

hsv = cv2.cvtColor(img2_fg, cv2.COLOR_BGR2HSV)

lower_red= np.array([0,58,130])
upper_red = np.array([255,255,255])

erosion = cv2.erode(mask,kernel,iterations = 3)
rmask = cv2.inRange(hsv, lower_red, upper_red)


mask2 = cv2.morphologyEx(rmask, cv2.MORPH_CLOSE, kernel)
final = cv2.bitwise_and(frame, frame, mask=mask2)
cv2.imshow('final',final)
cv2.imshow('original',frame)


k = cv2.waitKey(5) & 0xFF
if k == 27:
    break

cv2.destroyAllWindows()

VideoCapture so slow in reading video file.

Why is it if i read a video file using cv2.VideoCapture('video.avi') the fps is very very very low? I want the fps to be the same as when i play the video using a video player(30fps). What changes should i make to achieve this? Btw, i am using a raspberry pi 3 with python. import cv2 import numpy as np

cap = cv2.VideoCapture('Fchecking.avi')
kernel = np.ones((5,5), np.uint8)

while(1):

    # Take each frame
    ret, frame = cap.read()
    img2gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

   ret,mask = cv2.threshold(img2gray,140,255,cv2.THRESH_BINARY) 
    w3w = cv2.adaptiveThreshold(mask,255,cv2.ADAPTIVE_THRESH_MEAN_C,cv2.THRESH_BINARY,47,2)   
cv2.imshow("mask", mask)

mask_inv = cv2.bitwise_not(w3w) 

img2_fg = cv2.bitwise_and(frame, frame, mask=mask_inv)

hsv = cv2.cvtColor(img2_fg, cv2.COLOR_BGR2HSV)

lower_red= np.array([0,58,130])
upper_red = np.array([255,255,255])

erosion = cv2.erode(mask,kernel,iterations = 3)
rmask = cv2.inRange(hsv, lower_red, upper_red)


mask2 = cv2.morphologyEx(rmask, cv2.MORPH_CLOSE, kernel)
final = cv2.bitwise_and(frame, frame, mask=mask2)
cv2.imshow('final',final)
cv2.imshow('original',frame)


k = cv2.waitKey(5) & 0xFF
if k == 27:
    break

cv2.destroyAllWindows()

cv2.destroyAllWindows()

VideoCapture so slow in reading video file.

Why is it if i read a video file using cv2.VideoCapture('video.avi') the fps is very very very low? I want the fps to be the same as when i play the video using a video player(30fps). What changes should i make to achieve this? Btw, i am using a raspberry pi 3 with python. import cv2 import numpy as np

cap = cv2.VideoCapture('Fchecking.avi')
kernel = np.ones((5,5), np.uint8)

while(1):

    # Take each frame
    ret, frame = cap.read()
    img2gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    ret,mask = cv2.threshold(img2gray,140,255,cv2.THRESH_BINARY) 
    w3w = cv2.adaptiveThreshold(mask,255,cv2.ADAPTIVE_THRESH_MEAN_C,cv2.THRESH_BINARY,47,2)   
 cv2.imshow("mask", mask)

 mask_inv = cv2.bitwise_not(w3w) 

 img2_fg = cv2.bitwise_and(frame, frame, mask=mask_inv)

 hsv = cv2.cvtColor(img2_fg, cv2.COLOR_BGR2HSV)

 lower_red= np.array([0,58,130])
 upper_red = np.array([255,255,255])

 erosion = cv2.erode(mask,kernel,iterations = 3)
 rmask = cv2.inRange(hsv, lower_red, upper_red)


 mask2 = cv2.morphologyEx(rmask, cv2.MORPH_CLOSE, kernel)
 final = cv2.bitwise_and(frame, frame, mask=mask2)
 cv2.imshow('final',final)
 cv2.imshow('original',frame)


 k = cv2.waitKey(5) & 0xFF
 if k == 27:
     break

cv2.destroyAllWindows()
click to hide/show revision 4
None

updated 2018-01-31 09:36:27 -0600

berak gravatar image

VideoCapture so slow in reading video file.

Why is it if i read a video file using cv2.VideoCapture('video.avi') the fps is very very very low? I want the fps to be the same as when i play the video using a video player(30fps). What changes should i make to achieve this? Btw, i am using a raspberry pi 3 with python. python.

import cv2 import numpy as np

cap = cv2.VideoCapture('Fchecking.avi')
kernel = np.ones((5,5), np.uint8)

while(1):

    # Take each frame
    ret, frame = cap.read()
    img2gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    ret,mask = cv2.threshold(img2gray,140,255,cv2.THRESH_BINARY) 
    w3w = cv2.adaptiveThreshold(mask,255,cv2.ADAPTIVE_THRESH_MEAN_C,cv2.THRESH_BINARY,47,2)   
    cv2.imshow("mask", mask)

    mask_inv = cv2.bitwise_not(w3w) 

    img2_fg = cv2.bitwise_and(frame, frame, mask=mask_inv)

    hsv = cv2.cvtColor(img2_fg, cv2.COLOR_BGR2HSV)

    lower_red= np.array([0,58,130])
    upper_red = np.array([255,255,255])

    erosion = cv2.erode(mask,kernel,iterations = 3)
    rmask = cv2.inRange(hsv, lower_red, upper_red)


    mask2 = cv2.morphologyEx(rmask, cv2.MORPH_CLOSE, kernel)
    final = cv2.bitwise_and(frame, frame, mask=mask2)
    cv2.imshow('final',final)
    cv2.imshow('original',frame)


    k = cv2.waitKey(5) & 0xFF
    if k == 27:
        break

cv2.destroyAllWindows()

VideoCapture so slow in reading video file.

Why is it if i read a video file using cv2.VideoCapture('video.avi') the fps is very very very low? I want the fps to be the same as when i play the video using a video player(30fps). What changes should i make to achieve this? Btw, i am using a raspberry pi 3 with python.

import cv2 import numpy as np

cap = cv2.VideoCapture('Fchecking.avi')
kernel = np.ones((5,5), np.uint8)

while(1):

    # Take each frame
    ret, frame = cap.read()
    img2gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    ret,mask = cv2.threshold(img2gray,140,255,cv2.THRESH_BINARY) 
    w3w = cv2.adaptiveThreshold(mask,255,cv2.ADAPTIVE_THRESH_MEAN_C,cv2.THRESH_BINARY,47,2)   
    cv2.imshow("mask", mask)

    mask_inv = cv2.bitwise_not(w3w) 

    img2_fg = cv2.bitwise_and(frame, frame, mask=mask_inv)

    hsv = cv2.cvtColor(img2_fg, cv2.COLOR_BGR2HSV)

    lower_red= np.array([0,58,130])
    upper_red = np.array([255,255,255])

    erosion = cv2.erode(mask,kernel,iterations = 3)
    rmask = cv2.inRange(hsv, lower_red, upper_red)


    mask2 = cv2.morphologyEx(rmask, cv2.MORPH_CLOSE, kernel)
    final = cv2.bitwise_and(frame, frame, mask=mask2)
    cv2.imshow('final',final)
    cv2.imshow('original',frame)


    k = cv2.waitKey(5) & 0xFF
    if k == 27:
        break

cv2.destroyAllWindows()