logo
down
shadow

How to get frame feed of a video in OpenCV?


How to get frame feed of a video in OpenCV?

By : user4642879
Date : December 05 2020, 12:18 PM
I hope this helps . I'm assuming you want to store the frames. I would recommend std::vector (as GPPK recommends). std::vector allows you to dynamically create an array. The push_back(Mat()) function adds an empty Mat object to the end of the vector and the back() function returns the last element in the array (which allows cap to write to it).
The code would look like this:
code :


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)
How to crop a webcam feed frame using OpenCV and C++

How to crop a webcam feed frame using OpenCV and C++


By : Rach
Date : March 29 2020, 07:55 AM
will be helpful for those in need I don't like C interface of Open CV, so I'd suggest you a possible solution via C++ interface of Open CV 3.4.0
code :
#include <Windows.h>
#include <Vfw.h>
#include <string>
#include <iostream>
#include "opencv2\core\core.hpp"
#include "opencv2\imgproc\imgproc.hpp"
#include "opencv2\imgcodecs\imgcodecs.hpp"
#include "opencv2\highgui\highgui.hpp"

using namespace cv;
using namespace std;

int main()
{

    VideoCapture camera;
    camera.open(0);
    if (!camera.isOpened()) {
        cout << "Failed to open camera." << std::endl;
        return -1;
    }
    Mat frame, oMatCrop;

    while(1){ //Create loop for live streaming

        camera >> frame;
        oMatCrop=frame(cv::Rect(0,0,320,240));

        cv::namedWindow("Image",CV_WINDOW_FREERATIO);
        cv::imshow("Image", frame);

        cv::namedWindow("Cropped image",CV_WINDOW_FREERATIO);
        cv::imshow("Cropped image", oMatCrop);

        if (waitKey(50) == 27) {
            break;
        }
    }
    return 0;
}
OpenCV: Code to Reconnect a Disconnected Camera Feed is Working Fine but in the Front End Captured Video Frame is Not ge

OpenCV: Code to Reconnect a Disconnected Camera Feed is Working Fine but in the Front End Captured Video Frame is Not ge


By : Drox
Date : March 29 2020, 07:55 AM
Any of those help
Video feed is not getting stopped(more specifically in my case: that blank window is not going off) upon pressing 'q' from keyboard, although there is code written for this
code :
def work_with_captured_video():
while True:
    ret, frame = camera.read()
    if not ret:
        print("Camera is disconnected!")
        camera.release()
        return False
        break
    else:
        cv2.imshow('frame', frame)
        return True # Here You are returning the status.
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
def work_with_captured_video():
    while True:
        ret, frame = camera.read()
        if not ret:
            print("Camera is disconnected!")
            camera.release()
            return False
            #break --> Not required.
        else:
            cv2.imshow('frame', frame)

        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
     return True
while True:
    camera = cv2.VideoCapture('rtsp://<ip specific to my camera>')
    if camera.isOpened():
        print('Camera is connected')
        #call function
        response = work_with_captured_video()
        if response == False:
            time.sleep(10)
            continue
    else:
        print('Camera not connected')
        camera.release()
        time.sleep(10)
        continue
def work_with_captured_video(camera):
    while True:
        ret, frame = camera.read()
        if not ret:
            print("Camera is disconnected!")
            camera.release()
            return False
        else:
            cv2.imshow('frame', frame)

        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
    return True

while True:
    camera = cv2.VideoCapture('rtsp://<ip specific to my camera>')
    if camera.isOpened():
        print('Camera is connected')
        #call function
        response = work_with_captured_video(camera)
        if response == False:
            time.sleep(10)
            continue
    else:
        print('Camera not connected')
        camera.release()
        time.sleep(10)
        continue
How to draw a line on frame from live video feed in opencv c++

How to draw a line on frame from live video feed in opencv c++


By : user2863464
Date : March 29 2020, 07:55 AM
it fixes the issue As @Sunreef suggested, you can create separate cv::Mat to keep picture with lines only and display src combined with this picture
code :
// #0 NEW - add declaration of lines here so this Mat is visible in both onMouse and main scope
cv::Mat src, lines;

void onMouse(int event, int x, int y, int f, void*)
{        
    if (f == 3)
    {
        cout << "start x,y is : " << start_x << start_y << endl;
        int end_x = x;
        int end_y = y;
        cout << "end x,y  is : " << end_x << end_y << endl;

        // #1 NEW - draw line into lines instead of src
        cv::line(lines, cv::Point(start_x, start_y), cv::Point(end_x, end_y), Scalar(255), 2, 8, 0);

        // #2 NEW - remove unnecessary imshow here

        run_once = false;
     }
}

int main(int, char**)
{
    for (;;)
    {
        cap >> src; 

        // #3 NEW - init lines once, to be the same size, same type as src filled with zeros
        if(lines.empty()) lines = cv::Mat::zeros(src.size(), src.type());

        // #4 NEW - show lines combined with lines            
        imshow(winName, lines + src);

        if (waitKey(30) >= 0) break;
    }
    return 0;
}
Related Posts Related Posts :
  • C++ Dynamically Allocated Array; Size set by quantity of user input; Writing to a file;
  • enums to be defined as uint8_t variables in structure
  • C++ Overloaded Constructor issues
  • Fast CSV parser in C++
  • MFC GUI application rewrite - threading, messaging, Document/View, etc. Advice needed
  • saving data structure c++ to disk
  • Vector of pointers: some clarification needed
  • scaling a bitmap without losing quality
  • How to evaluate a function directly?
  • QNetworkAccessManager: How to change post data at createRequest function
  • Returning std::move of a local variable
  • Is there a fast linear SVM library with a good C++ interface?
  • What is the purpose of name mangling in C++?
  • C++ Why the void function is not working eventhough I called it?
  • How the pointer and the pointer's adress can share the same memory adress?
  • error C2220: warning treated as error - no 'object' file generated
  • exception of strcpy function in c++ console program
  • How to access USB barcode scanner data directly from USB port using C/C++ without driver
  • Under which circumstances will std::vector.clear() call a destructor?
  • Template partial specialisation and dependent names
  • best way to share data between c codes
  • C++ ignores if statement conditions
  • How to set the argv[ ] to be case-insensitive in a Win32 Console Application?
  • How to fix error "clang: error: linker (via gcc) command failed with exit code 1 (use -v to see invocation)"?
  • C++ How do I print a .txt file verbatim?
  • Creating two dimensional array of class
  • How do I correctly use COMMTIMEOUTS with OVERLAPPED IO mode reading from a Serial port
  • An assert macro which expands to static_assert when possible?
  • How to write a copyconstructor for a class which has HANDLE as a member in win32 c++ application?
  • C++ saving info such as tree in a file
  • Transforming an expression template tree
  • How to overload an operator with multiple parameters like a + b + c?
  • C++ 11 with Raspberry Pi performances
  • Make a C++ class look like a numpy array using swig
  • Postfix incrementer overloading for nested enumerated types
  • Is there a tidy way of associating metadata with functions in C++
  • QObject::installEventFilter(): Cannot filter events for objects in a different thread
  • LNK2005 error with Zxing C++
  • C++ Doubly Linked List with Pointers: Object of class isn't constructed properly
  • Using a random string generator in c++ constructor
  • What should I use instead of void as one of the alternative types in an variant?
  • C++ return value from multithreads using reference
  • How to connect multiple TCP IP clients to same server port using c++
  • Defaul compiler generates the reference operator (In C++)?
  • Unable to change directory time stamp after using FILE_FLAG_BACKUP_SEMANTICS
  • vector handling displaying output
  • WSAGetLastError returns WSAENOTSOCK - Cause?
  • C++: How to overload pow for user type?
  • C++ using arrays as multidimensional despite initalising it as 1D with pointer
  • How negate std::is_integral for use in tag dispatch?
  • Retrieve serial number from USB memory (Windows environment c++)
  • g++ error: invalid preprocessing directive #INCLUDE
  • C++ What is the std::for_each() function parameter type?
  • C++: Read individual lines from text file, sort words alphabetically
  • Saving 'this' address into a variable
  • c++ command line arguments in ubuntu terminal
  • Convert "Cartesian coordinates" to "polar coordinates with respect to user specified origin"
  • In what order are local scoped objects destructed?
  • How to use SDL_MapRGB with SDL 2.0
  • how compiler and interpreter work in case of array declaration
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org