Close Menu
Techs Slash

    Subscribe to Updates

    Get the latest creative news from FooBar about art, design and business.

    What's Hot

    Designing for Milliseconds: The Precision Tech Behind AviatorĀ 

    April 6, 2026

    The One App You Only Open When Something Is Already Happening

    April 6, 2026

    375 Suppressor Guide: Enhancing Performance of the 375 Raptor Platform

    April 6, 2026
    Facebook X (Twitter) Instagram
    Techs Slash
    • Home
    • News
      • Tech
      • Crypto News
      • Cryptocurrency
    • Entertainment
      • Actors
      • ANGEL NUMBER
      • Baby Names
      • Beauty
      • beauty-fashion
      • facebook Bio
      • Fitness
      • Dubai Tour
    • Business
      • Business Names
    • Review
      • Software
      • Smartphones & Apps
    • CONTRIBUTION
    Facebook X (Twitter) Instagram
    Techs Slash
    Home»python»Python 3 OpenCV Script to Process MP4 Video Images and Perform Smoothing, Edge Detection & Bitwise Operations
    python

    Python 3 OpenCV Script to Process MP4 Video Images and Perform Smoothing, Edge Detection & Bitwise Operations

    Ranveer KumarBy Ranveer KumarOctober 20, 2022No Comments3 Mins Read
    Facebook Twitter Pinterest LinkedIn Tumblr Email

    Warning: Trying to access array offset on value of type bool in /home/cadesimu/techsslash.com/wp-content/themes/smart-mag/partials/single/featured.php on line 78
    Share
    Facebook Twitter LinkedIn Pinterest Email

    Python 3 OpenCV Script to Process MP4 Video Images and Perform Smoothing, Edge Detection & Bitwise Operations

    # importing the necessary libraries
    import cv2
    import numpy as np
    
    # Creating a VideoCapture object to read the video
    cap = cv2.VideoCapture('sample.mp4')
    
    
    # Loop until the end of the video
    while (cap.isOpened()):
    
    # Capture frame-by-frame
    ret, frame = cap.read()
    frame = cv2.resize(frame, (540, 380), fx = 0, fy = 0,
    interpolation = cv2.INTER_CUBIC)
    
    # Display the resulting frame
    cv2.imshow('Frame', frame)
    
    # conversion of BGR to grayscale is necessary to apply this operation
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    
    # adaptive thresholding to use different threshold
    # values on different regions of the frame.
    Thresh = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_MEAN_C,
    cv2.THRESH_BINARY_INV, 11, 2)
    
    cv2.imshow('Thresh', Thresh)
    # define q as the exit button
    if cv2.waitKey(25) & 0xFF == ord('q'):
    break
    
    # release the video capture object
    cap.release()
    # Closes all the windows currently opened.
    cv2.destroyAllWindows()
    
    
    # importing the necessary libraries
    import cv2
    import numpy as np
    
    # Creating a VideoCapture object to read the video
    cap = cv2.VideoCapture('sample.mp4')
    
    
    # Loop until the end of the video
    while (cap.isOpened()):
    # Capture frame-by-frame
    ret, frame = cap.read()
    frame = cv2.resize(frame, (540, 380), fx = 0, fy = 0,
    interpolation = cv2.INTER_CUBIC)
    
    # Display the resulting frame
    cv2.imshow('Frame', frame)
    
    # using cv2.Gaussianblur() method to blur the video
    
    # (5, 5) is the kernel size for blurring.
    gaussianblur = cv2.GaussianBlur(frame, (5, 5), 0)
    cv2.imshow('gblur', gaussianblur)
    
    # define q as the exit button
    if cv2.waitKey(25) & 0xFF == ord('q'):
    break
    
    # release the video capture object
    cap.release()
    
    # Closes all the windows currently opened.
    cv2.destroyAllWindows()
    
    
    # importing the necessary libraries
    import cv2
    import numpy as np
    
    # Creating a VideoCapture object to read the video
    cap = cv2.VideoCapture('sample.mp4')
    
    
    # Loop until the end of the video
    while (cap.isOpened()):
    # Capture frame-by-frame
    ret, frame = cap.read()
    
    frame = cv2.resize(frame, (540, 380), fx = 0, fy = 0,
    interpolation = cv2.INTER_CUBIC)
    
    # Display the resulting frame
    cv2.imshow('Frame', frame)
    
    # using cv2.Canny() for edge detection.
    edge_detect = cv2.Canny(frame, 100, 200)
    cv2.imshow('Edge detect', edge_detect)
    
    # define q as the exit button
    if cv2.waitKey(25) & 0xFF == ord('q'):
    break
    
    # release the video capture object
    cap.release()
    # Closes all the windows currently opened.
    cv2.destroyAllWindows()
    
    
    # importing the necessary libraries
    import cv2
    import numpy as np
    
    # Creating a VideoCapture object to read the video
    cap = cv2.VideoCapture('sample.mp4')
    
    
    # Loop until the end of the video
    while (cap.isOpened()):
    # Capture frame-by-frame
    ret, frame = cap.read()
    frame = cv2.resize(frame, (540, 380), fx = 0, fy = 0,
    interpolation = cv2.INTER_CUBIC)
    
    # Display the resulting frame
    cv2.imshow('Frame', frame)
    
    # conversion of BGR to grayscale is necessary to apply this operation
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    
    _, mask = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)
    
    # apply NOT operation on image and mask generated by thresholding
    BIT = cv2.bitwise_not(frame, frame, mask = mask)
    cv2.imshow('BIT', BIT)
    
    # define q as the exit button
    if cv2.waitKey(25) & 0xFF == ord('q'):
    break
    
    # release the video capture object
    cap.release()
    
    # Closes all the windows currently opened.
    cv2.destroyAllWindows()
    
    
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Ranveer Kumar
    • Website

    Related Posts

    JSONDecodeError: Expecting value: line 1 column 1 (char 0)

    December 18, 2023

    Why does math.log result in ValueError: math domain error?

    December 17, 2023

    “inconsistent use of tabs and spaces in indentation” [duplicate]

    December 16, 2023
    Leave A Reply Cancel Reply

    Top Posts

    Sapne Me Nahane Ka Matlab

    March 18, 2024

    Sapne Me Nagn Stri Dekhna

    March 18, 2024

    Self Reliance: Release Date, Cast, Plot, Trailer, and More Information

    March 18, 2024

    Subscribe to Updates

    Get the latest creative news from FooBar about art, design and business.

    ABOUT TECHSSLASH

    Welcome to Techsslash! We're dedicated to providing you with the best of technology, finance, gaming, entertainment, lifestyle, health, and fitness news, all delivered with dependability.

    Our passion for tech and daily news drives us to create a booming online website where you can stay informed and entertained.

    Enjoy our content as much as we enjoy offering it to you

    Most Popular

    Sapne Me Nahane Ka Matlab

    March 18, 2024

    Sapne Me Nagn Stri Dekhna

    March 18, 2024

    Self Reliance: Release Date, Cast, Plot, Trailer, and More Information

    March 18, 2024
    CONTACT DETAILS

    Phone: +92-302-743-9438
    Email: contact@serpinsight.com

    Our Recommendation

    Here are some helpfull links for our user. hopefully you liked it.

    kakekmerah4d

    Techs Slash
    Facebook X (Twitter) Instagram Pinterest
    • Home
    • About us
    • contact us
    • Affiliate Disclosure
    • Privacy Policy
    • Disclaimer
    • Terms and Conditions
    • Write for us
    • Daman Game
    © 2026 Techsslash. All Rights Reserved

    Type above and press Enter to search. Press Esc to cancel.