logo
down
shadow

How to apply a color cast to a video frame in OpenCV Python?


How to apply a color cast to a video frame in OpenCV Python?

By : user2172840
Date : October 22 2020, 08:10 PM
it fixes the issue I'm very new to image processing and OpenCV. I'm working on a helper-function to assist in tuning some key-frame detection parameters. , Two simple options come to mind.
Let's start with this code:
code :
import cv2
import numpy as np

frame = cv2.imread('lena3.png')
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
result = np.zeros_like(frame)
result[...,0] = gray
cv2.imwrite('shaded_lena.png', result)
blank = np.zeros_like(gray)

shaded = [
    cv2.merge([gray, blank, blank])
    , cv2.merge([blank, gray, blank])
    , cv2.merge([blank, blank, gray])
    , cv2.merge([gray, gray, blank])
    , cv2.merge([gray, blank, gray])
    , cv2.merge([blank, gray, gray])
]

cv2.imwrite('shaded_lena_all.png', np.hstack(shaded))


Share : facebook icon twitter icon
How to process images of a video, frame by frame, in video streaming using OpenCV and Python

How to process images of a video, frame by frame, in video streaming using OpenCV and Python


By : betul
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further After reading the documentation of VideoCapture. I figured out that you can tell VideoCapture, which frame to process next time we call VideoCapture.read() (or VideoCapture.grab()).
The problem is that when you want to read() a frame which is not ready, the VideoCapture object stuck on that frame and never proceed. So you have to force it to start again from the previous frame.
code :
import cv2

cap = cv2.VideoCapture("./out.mp4")
while not cap.isOpened():
    cap = cv2.VideoCapture("./out.mp4")
    cv2.waitKey(1000)
    print "Wait for the header"

pos_frame = cap.get(cv2.cv.CV_CAP_PROP_POS_FRAMES)
while True:
    flag, frame = cap.read()
    if flag:
        # The frame is ready and already captured
        cv2.imshow('video', frame)
        pos_frame = cap.get(cv2.cv.CV_CAP_PROP_POS_FRAMES)
        print str(pos_frame)+" frames"
    else:
        # The next frame is not ready, so we try to read it again
        cap.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, pos_frame-1)
        print "frame is not ready"
        # It is better to wait for a while for the next frame to be ready
        cv2.waitKey(1000)

    if cv2.waitKey(10) == 27:
        break
    if cap.get(cv2.cv.CV_CAP_PROP_POS_FRAMES) == cap.get(cv2.cv.CV_CAP_PROP_FRAME_COUNT):
        # If the number of captured frames is equal to the total number of frames,
        # we stop
        break
How to get video frame by frame from stream using openCV and python

How to get video frame by frame from stream using openCV and python


By : Dennis Preston
Date : March 29 2020, 07:55 AM
this one helps. http://answers.opencv.org/question/24154/how-to-using-opencv-api-get-web-video-stream/
You should be able to just cap = cv2.VideoCapture('yourStreamURIHere')
code :
cap = cv2.VideoCapture('http://hello:goodbye@127.0.0.1/?action=stream?otherparamshere)
get frame from video with CV_CAP_PROP_POS_FRAMES in opencv python

get frame from video with CV_CAP_PROP_POS_FRAMES in opencv python


By : B4t M4n
Date : March 29 2020, 07:55 AM
I hope this helps . I am trying to detect a (photography) flash in a video using OpenCV. , From opencv-doc:
How to get frame from video by its index via OpenCV and Python?

How to get frame from video by its index via OpenCV and Python?


By : Rdy mxTrrr
Date : March 29 2020, 07:55 AM
To fix this issue Use VideoCapture::set() with CAP_PROP_POS_FRAMES property id to set the position of the frame to be read.
code :
myFrameNumber = 50
cap = cv2.VideoCapture("video.mp4")

# get total number of frames
totalFrames = cap.get(cv2.CAP_PROP_FRAME_COUNT)

# check for valid frame number
if myFrameNumber >= 0 & myFrameNumber <= totalFrames:
    # set frame position
    cap.set(cv2.CAP_PROP_POS_FRAMES,myFrameNumber)

while True:
    ret, frame = cap.read()
    cv2.imshow("Video", frame)
    if cv2.waitKey(20) & 0xFF == ord('q'):
        break

cv2.destroyAllWindows()
How to get previous frame of a video in opencv python

How to get previous frame of a video in opencv python


By : Taj Sayyad
Date : March 29 2020, 07:55 AM
I hope this helps . There is no specific function in OpenCV to access the previous frame. Your problem can be solved by calling cap.read() once before entering the while loop. Use a variable prev_frame to store the previous frame just before reading the new frame. Finally, as a good practice, you should verify that the frame was properly read, before doing computations on it. Your code could look something like:
code :
import cv2
import numpy as np

cap = cv2.VideoCapture('video3.mov')
ret, frame = cap.read()

while(cap.isOpened()):
    prev_frame=frame[:]
    ret, frame = cap.read()
    if ret:
        gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

        #detect key feature points
        sift = cv2.xfeatures2d.SIFT_create()
        kp, des = sift.detectAndCompute(gray, None)

        #some magic with prev_frame

        #draw key points detected
        img=cv2.drawKeypoints(gray,kp,gray, flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)

        cv2.imshow("grayframe",img)
    else:
        print('Could not read frame')

    if cv2.waitKey(100) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()
Related Posts Related Posts :
  • Submitting login form with scrapy
  • How do i edit the favicon in the Browsable API in Django REST framework?
  • multiprocessing.Pool.map_async doesn't seem to... do anything at all?
  • Python Selenium: Stale Element Reference Exception Error
  • Datetime conversion - How to extract the inferred format?
  • Import YAML variables automatically?
  • How to create a powershell shortcut for my python file
  • Python's 'set' operator doesn't work with numpy.nan
  • Pass object fields and one2many fields on same method - Odoo v8
  • Select columns based on column name and location in Pandas
  • Standardizing timeseries in Pandas using interpolation
  • How many tweets can be collected?
  • how format specifier taking value while tuple list is passed
  • How to print a numpy array with data type?
  • Timeout child thread for python3
  • How can I regroup a dataframe and accumulate a colume's values?
  • Bulk Insert into SQL Server with Python not working
  • Removing last rows of each group based on condition in a pandas dataframe
  • Why the css file can not be found in Django template?
  • targeting center of mass - scipy / numpy
  • Foursquare - get tips from VENUE_ID
  • Unpack a dictionary to format
  • encoding special characters in python2
  • Replacing integers with NaN results in the entire column becoming float dtype
  • Python 3.6 - BeautifulSoup4, parse table AttributeError: ResultSet object has no attribute 'findAll'
  • Convert panda date list to python list of date strings
  • escape response from Scrapy to parse json
  • How to create a same dropdown menu for different labels?
  • Why are some python variables uppercase whereas others are lowercase?
  • Machine Learning, What are the common techniques for feature engineering and presenting the model?
  • Modify value of a Django form field during clean() and validate again
  • Heroku Django app can't start up -- 'No module named site'
  • Getting list of dates (excluding weekends)
  • Im trying to create the regular expression to include the text and not the href
  • Python file.readline(2) reads first 2 charectars
  • Groupby with handling empty bin in python
  • Modifying Gcode
  • calling a value in a dictionary within a dictionary (reading a json file)
  • Bouncing ball invalid syntax why is that?
  • Python making a counter
  • Python rstrip and split
  • What does the String mean in numpy.r_?
  • How to correctly extend variable __all__ in a __init__.py?
  • Python behaves weird with piped input
  • Python 3 two dimensional list comprehension
  • How to slice image by broadcasting slices? Error: 'only integer scalar arrays can be converted to a scalar index' in pyt
  • (Python Beginner) Need a start on classes
  • IndexError: At least one sheet must be visible
  • How to solve a system of linear equations over the nonnegative integers?
  • Pandas keep the most complete rows
  • "List index out of range" error in Python Memory Match game
  • Numpy: how to use argmax results to get the actual max?
  • Google Cloud Dataflow can't import 'google.cloud.datastore'
  • Calculate pandas DataFrame column by custom routine which accepts dictionary as input
  • Connect to a Class Method by it's method name holded into a var in a for loop in python
  • PyQt5 signals and threading.Timer
  • Replace 2 characters in a string in python
  • Passing command line arguments from a folder script to a file script
  • Understand the syntaxe X[Y == c] in Numpy
  • Optimize beginner python script about substring replacement
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org