Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8938693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:41:22+00:00 2026-06-15T10:41:22+00:00

Hi I am trying to play a video using the following code: //#include <stdio.h>

  • 0

Hi I am trying to play a video using the following code:

//#include <stdio.h>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
//#include <iostream>

using namespace cv;

int main(int argc, char** argv)
{
    string filename = "anime.avi";
    VideoCapture capture(filename);
    Mat frame;
    if( !capture.isOpened() )
        throw "Error when reading steam_avi";
    namedWindow( "w", 1);
    for( ; ; )
    {
        capture >> frame;
        if(!frame)
            break;
        imshow("w", frame);
        waitKey(20); // waits to display frame
    }
    waitKey(0); // key press to close window
    // releases and window destroy are automatic in C++ interface
}

When I run it though, I get the following errors:
project.cpp: In function ‘int main(int, char**)’:

project.cpp:23:13: error: no match for ‘operator!’ in ‘!frame’
project.cpp:23:13: note: candidates are:
project.cpp:23:13: note: operator!(bool) <built-in>
project.cpp:23:13: note:   no known conversion for argument 1 from ‘cv::Mat’ to ‘bool’
/usr/local/include/opencv2/core/operations.hpp:2220:20: note: bool cv::operator!(const cv::Range&)
/usr/local/include/opencv2/core/operations.hpp:2220:20: note:   no known conversion for argument 1 from ‘cv::Mat’ to ‘const cv::Range&’

Could you possibly help. I’ve been on this for hours without success 🙁

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T10:41:23+00:00Added an answer on June 15, 2026 at 10:41 am

    Because there is no operator! overloaded for class cv::Mat. In the documentation, it not said clearly, what should happen with the image in case of acquisition failed. That’s the implementation of cv::VideoCapture::operator>> from cap.cpp:

    VideoCapture& VideoCapture::operator >> (Mat& image)
    {
        if(!grab())
            image.release();
        else
            retrieve(image);
        return *this;
    }
    

    Now go to documentation on cv::Mat:release. And let’s double check it’s implementation from the mat.hpp:

    inline void Mat::release()
    {
        if( refcount && CV_XADD(refcount, -1) == 1 )
            deallocate();
        data = datastart = dataend = datalimit = 0;
        size.p[0] = 0;
        refcount = 0;
    }
    

    Hence, finally, you can check the data pointer to find out, whether the grab was successful:

    if (!frame.data) break;
    

    However, I recommend to use function-style call cv::VideoCapture::read in this case, since it explicitly returns whether it was successful, or not:

    if (!capture.read(frame)) break;
    

    HTH

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to play video(.mp4) in my app using following code. NSString *doc
I'm trying to play video from youtube using this code but I get this
So I'm trying to play a video and the following code has worked for
I am using VideoView trying to play video. But when I use this code
I am trying to play a video file using JMF but it gives me
I'm trying to play a video using opencv (the video is an avi file
I'm trying to play two videos continuously using MPMoviePlayer. I let the second video
While trying to play video using media player, I am getting this error: Unable
I'm trying to do the following: receive video stream using gstreamer and process it
I'm trying to play a video using vlcj inside a JPanel but it doesn't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.