Ask Your Question
0

unable to read memory

asked 2016-02-10 01:35:14 -0600

busrakkk gravatar image

updated 2016-02-10 08:30:51 -0600

I use opencv 3.1.0 and have a function at myClass.cpp below;

void initialize(Mat frame);

and i call the function from main like;

myClass temp  = myClass::myClass();
temp.initialize(current_frame);

constructer works and assigns correct values to temp also current_frame is initialized and its values are correct at main class but when i call the function the program breaks and when i debugged i saw at myClass.cpp the function cannot read the values of frame as i give the parameter to the function. At the inside of initialize(Mat frame) it says "unable to read memory" for all parameters of frame(e.g size, coloumns, rows ...).

any help or suggestion?

Edit: I added a sample code that i get the same error below;

Main.cpp

#include "Modifier.hpp"

using namespace cv;
using namespace std;

Mat image;

int main(int argc, char* argc){
   string imageName("../image.png");
   if (argc > 1) {
      imageName = argv[1];
   }
   image = imread(imageName.c_str(), IMREAD_COLOR);
   if(image.empty()){
      cout << "image is empty" << endl;
      return -1;
   }
   Modify mdf(image);
   if(mdf.getImage().empty()){
      cout << "image is empty" << endl;
      return -1;
   }

   // recently added line
   mdf.myFunc();
}

Modifier.cpp

#include "Modifier.hpp"

using namespace cv;

Modify::Modify(Mat img){
   this->image.upload(img);
}

GpuMat Modify::getImage(){
   return this->image;
}

//recently added line
void Modify::myFunc(){
}

Modifier.hpp

#include <opencv2\core.hpp>
#include <opencv2\highgui.hpp>
#include <opencv\imgcodecs.hpp>
#include <opencv2\imgproc.hpp>
#include <opencv2\core\cuda.hpp>

using namespace cv;
using namespace cv::cuda;

class Modify
{
public:
   Modify(Mat img);
   GpuMat getImage();
   //recently added line
   void myFunc();

protected:
   GpuMat image;

since it is unable to read the frame's values cannot assign values to parameters. hope it helps.

edit retag flag offensive close merge delete

Comments

your code is a bit incomplete, we don't see, what happens inside void initialize(Mat frame);

could you update it ?

berak gravatar imageberak ( 2016-02-10 01:55:29 -0600 )edit

I am not allowed to copy the code but i can say that the error occurs at the beggining of the function; first line is "vidSize = current_frame.size();" and cannot even execute this line.

busrakkk gravatar imagebusrakkk ( 2016-02-10 02:03:30 -0600 )edit

then, how can we help you ?

try to make a minimal example, (without copying anything)

berak gravatar imageberak ( 2016-02-10 02:07:31 -0600 )edit

what is current ?

berak gravatar imageberak ( 2016-02-10 02:45:20 -0600 )edit

sorry, i missed out. current is one of the global variables of myClass, its type is GpuMat. If you need more info i can provide as much as i am able to

busrakkk gravatar imagebusrakkk ( 2016-02-10 02:52:29 -0600 )edit

Please, either add your code here or either accept that people cannot help out. How can we figure out errors if your not allowed to add a minimal code sample containing the error ...

StevenPuttemans gravatar imageStevenPuttemans ( 2016-02-10 05:48:28 -0600 )edit

BTW is there a reason why you have a seperate initialize function and you just don't initialize everything in the constructor of the class? It could be reduced to myClass temp = myClass::myClass(current_frame); fairly easy. Also, I suggest you to make clones of the data to ensure that it is not some sketchy pointer accessing problem ...

StevenPuttemans gravatar imageStevenPuttemans ( 2016-02-10 05:50:37 -0600 )edit

initialize() method is for initializing another features of the object and runs some different algorithms, i've just name it as initialize. Sorry for the mess, i'm editing the code, writing a sample that i get the same error.

busrakkk gravatar imagebusrakkk ( 2016-02-10 05:59:07 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-02-10 07:42:54 -0600

This is OpenCV 3.1 right? If so start by replacing

#include <opencv2\core\core.hpp>
#include <opencv2\highgui.hpp>
#include <opencv\imgcodecs.hpp>
#include <opencv2\imgproc\imgproc.hpp>

into

#include <opencv2\core.hpp>
#include <opencv2\highgui.hpp>
#include <opencv\imgcodecs.hpp>
#include <opencv2\imgproc.hpp>

Then start by defining the includes on only a single place, too much overlap now. A common ground could be to add them to the Modifier.h because it is included in every other file. Also rename that file to Modifier.hpp since you want a C++ compatible header file.

Then report back if the issues still occur :)

edit flag offensive delete link more

Comments

Thank you for your reply :) Your suggestion worked for the code but when I modify it as you can see from above the issue still accurs for new function. Inside the Modifier.cpp it says "unable to read memory" for all values of all global variables of the object.

busrakkk gravatar imagebusrakkk ( 2016-02-10 08:18:17 -0600 )edit

That is because of the fact that you are using #include <opencv2\core\cuda.hpp>. You do not need to include that explicitly...

StevenPuttemans gravatar imageStevenPuttemans ( 2016-02-10 08:55:27 -0600 )edit

It is end of the shift now, i'll start with try and give feedback tomorrow :)

busrakkk gravatar imagebusrakkk ( 2016-02-10 09:04:26 -0600 )edit

To use GpuMat I have to add cuda.hpp,am i right?

busrakkk gravatar imagebusrakkk ( 2016-02-10 23:56:22 -0600 )edit
1

Well you should include the correct cuda header, which can be one of the following modules starting with cuda prefix and you should add using namespace cv::cuda;. But you should never include cuda headers inside the specific folders like #include <opencv2\core\cuda.hpp>. They are implicitly called when necessary from the global headers. Including them manually will again lead to conflicts.

StevenPuttemans gravatar imageStevenPuttemans ( 2016-02-11 04:31:23 -0600 )edit
1

Thanx, I fixed the cuda headers and it seems working right now at least number of errors decreased:)

busrakkk gravatar imagebusrakkk ( 2016-02-11 06:52:44 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-02-10 01:35:14 -0600

Seen: 2,215 times

Last updated: Feb 10 '16