Home > Java > body text

Open CV VideoCapture reading method

王林
Release: 2024-02-10 18:06:08
forward
661 people have browsed it

php editor Banana today introduces a method to open CV VideoCapture to read. In the field of computer vision, VideoCapture is a commonly used class for reading image frames from video files or cameras. By using the VideoCapture class, we can easily obtain the video stream and perform subsequent image processing and analysis. In this article, we will detail how to use the VideoCapture class to open and read video files or camera image frames. Whether you are a beginner or an experienced developer, you can read this article to learn how to use the VideoCapture class to process video data. Let’s take a look!

Question content

I am using an application called android studio to write all my code. I wrote the following code:

mat fieldimage = new mat();
videocapture.read(fieldimage);
Copy after login

But the read method of the videocapture object returns a Boolean value. So (if I'm correct), this code should throw an error. However, android studio doesn't throw an error. Does this code throw an error? If so, can this code replace it?

Mat fieldImage = new Mat();
boolean finishedCapturing =  videoCapture.read(fieldImage);
while(!finishedCapturing) {
finishedCapturing =  videoCapture.read(fieldImage);
}
Copy after login

Solution

First of all, if any method has a return value, there is no need for you to get the value. Any IDE usually won't give an error if you don't get the return value. But if a method gives you a return value, you should accept it and handle it as expected by the method.

For your case, videocapture's javadoc states that the return value indicates whether the frame can be captured.

So in your case you can do something like this

Mat fieldImage = new Mat();
boolean hasReadFrame = true;
// Have a do-while loop to only have once the read call
do {
    // Check if a frame has read
    hasReadFrame =  videoCapture.read(fieldImage);
    // after reading, you could do some more logic with the fieldImage
} while (hasReadFrame);
Copy after login

Of course, you'll need to add error/exception handling where needed.

The above is the detailed content of Open CV VideoCapture reading method. For more information, please follow other related articles on the PHP Chinese website!

source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!