Ask Your Question
0

unable to read memory

asked Feb 10 '16

busrakkk gravatar image

updated Feb 10 '16

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.

Preview: (hide)

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 (Feb 10 '16)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 (Feb 10 '16)edit

then, how can we help you ?

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

berak gravatar imageberak (Feb 10 '16)edit

what is current ?

berak gravatar imageberak (Feb 10 '16)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 (Feb 10 '16)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 (Feb 10 '16)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 (Feb 10 '16)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 (Feb 10 '16)edit

1 answer

Sort by » oldest newest most voted
0

answered Feb 10 '16

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 :)

Preview: (hide)

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 (Feb 10 '16)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 (Feb 10 '16)edit

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

busrakkk gravatar imagebusrakkk (Feb 10 '16)edit

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

busrakkk gravatar imagebusrakkk (Feb 11 '16)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 (Feb 11 '16)edit
1

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

busrakkk gravatar imagebusrakkk (Feb 11 '16)edit

Question Tools

1 follower

Stats

Asked: Feb 10 '16

Seen: 2,396 times

Last updated: Feb 10 '16