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

  • SEARCH
  • Home
  • 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 6175823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:59:27+00:00 2026-05-23T23:59:27+00:00

I’m making simple webcam program using OpenCV 2.3 and got stuck by the runtime

  • 0

I’m making simple webcam program using OpenCV 2.3 and got stuck by the runtime error. Any idea will be appreciated.

Compile passes but upon running, I get the following error (at cvCopyImage/cvResize in ‘read’ function in the code below).

error:

OpenCV Error: Bad argument (Unknown array type) in cvarrToMat, file /usr/local/src/OpenCV/OpenCV-2.3.0/modules/core/src/matrix.cpp, line 641
terminate called after throwing an instance of 'cv::Exception'
  what():  /usr/local/src/OpenCV/OpenCV-2.3.0/modules/core/src/matrix.cpp:641: error: (-5) Unknown array type in function cvarrToMat

code excerpt:

#include <iostream>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"

using namespace std;
using namespace cv;

Mat* SampleClassA::dispImg = NULL;

int read()
{
    Mat* sharedImg;
    sharedImg = getFrame();
    if (sharedImg)
    {
        if (dispImg == NULL)
        {
            SampleClassA::dispImg = sharedImg;
        }
    cvCopyImage(sharedImg, SampleClassA::dispImg); // Crashes here.
    cvResize(sharedImg, SampleClassA::classifyImg); // Can crash here too when cvCopyImage is commented out.
    }
    sleep(100);
    return 1;
}

Mat* getFrame()
//IplImage* ReadRealTime::getFrame()
{
    if (!capture.isOpened()) // Actual capturing part is omitted here.
    {
        return NULL;
    }
    Mat frame;
    capture >> frame;
    return &frame;
}
</code>

My guess is there’s something wrong either/both in the way I use Mat, or pointer. I’m still new both to OpenCV and C/C++ pointer (I’ve got an insightful comment in another question Can't save an image captured from webcam (imwrite compile error with OpenCV 2.3) to point out possible “dangling pointer”, but is this time the same?).

  • 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-05-23T23:59:28+00:00Added an answer on May 23, 2026 at 11:59 pm

    The problem is that you are returning a pointer to a stack allocated variable, which is automatically destroyed at the end of the function.

      // ...
      Mat frame;
      capture >> frame;
      return &frame;
    } // frame destroyed is at the end of the function yet you return a pointer to it!
    

    You need to allocate the frame on the heap so that it will live on past the end of the function:

      // ...
      Mat* frame = new Mat(); // Maybe this needs parameters
      capture >> *frame;
      return frame;
    }
    

    Remember that you need to delete the frame at a later point or your application will leak memory.

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

Sidebar

Related Questions

I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an XML file, the creators of it stuck in a bunch social

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.