473,406 Members | 2,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Beginner having trouble with invalid memory

The following code is sending me into an Access violation reading location 0x025e2000 - I'm a novice programmer and I'm hoping somebody can point me in the right direction

Expand|Select|Wrap|Line Numbers
  1. CvCapture * Capture=NULL;
  2. Capture = cvCaptureFromCAM(-1);
  3.  
  4. IplImage* FrameImage = 0;    
  5. IplImage* MirrorImage = 0;    
  6.  
  7. for(;;)
  8.     {
  9.         FrameImage = cvQueryFrame(Capture);
  10.  
  11.         MirrorImage = cvCloneImage(FrameImage);
  12.         cvFlip(MirrorImage, NULL, 1);
  13.  
  14. int b, r, g;    //colour channels
  15.         int x, y;        //For indexing through image
  16.  
  17.         cvNamedWindow( "OutPut", CV_WINDOW_AUTOSIZE );
  18.  
  19.         for ( x = 0; x < MirrorImage->width; x++ )
  20.         {
  21.             for ( y = 0; y < MirrorImage->height; y++ )
  22.             {
  23.                 b = ((uchar *)(MirrorImage->imageData + x*MirrorImage->widthStep))[y*MirrorImage->nChannels+0];
  24.                 g = ((uchar *)(MirrorImage->imageData + x*MirrorImage->widthStep))[y*MirrorImage->nChannels+1];
  25.                 r = ((uchar *)(MirrorImage->imageData + x*MirrorImage->widthStep))[y*MirrorImage->nChannels+2];
  26.  
  27.                 if ( !( g > 170 && r < 150 && b < 150 ) )
  28.                     {
  29.                     (FrameImage->imageData + x*FrameImage->widthStep)[y*FrameImage->nChannels+0]=(MirrorImage->imageData + x*MirrorImage->widthStep)[y*MirrorImage->nChannels+0];
  30.                     (FrameImage->imageData + x*FrameImage->widthStep)[y*FrameImage->nChannels+1]=(MirrorImage->imageData + x*MirrorImage->widthStep)[y*MirrorImage->nChannels+1];
  31.                     (FrameImage->imageData + x*FrameImage->widthStep)[y*FrameImage->nChannels+2]=(MirrorImage->imageData + x*MirrorImage->widthStep)[y*MirrorImage->nChannels+2];
  32.                     }
  33.             }
  34.         }
  35.         cvShowImage(WinName, FinImage);
  36.         cvShowImage("OutPut", FrameImage);
  37. }
  38.  
I'm trying to achieve a green screen application, but the code falls over while indexing through the image pixels, at x=482, y=64.

I look forward to your wisdom.
Feb 15 '11 #1
4 2297
weaknessforcats
9,208 Expert Mod 8TB
FrameImage and MirrorImpage are pointers. These pointers contain 0. The address 0 is not in your process address space, hence the Access Violation.

Either create FrameImage and MirrorImage as stack arrays ot allocate the memory yourself and use them as heap arrays.

In short, you will get errors whenever you try to access memory that your process does not own.
Feb 15 '11 #2
expanding the above answer in case it's not clear to you:

"...allocate the memory yourself and use them as heap arrays."

this means use the new keyword to allocate the memory
Feb 16 '11 #3
newb16
687 512MB
They are not null, they are assigned something.
FrameImage = cvQueryFrame(Capture);
MirrorImage = cvCloneImage(FrameImage);
The other thing is that you never free/release them after you process them.
Feb 16 '11 #4
weaknessforcats
9,208 Expert Mod 8TB
I didn't see that. oops.

However, you can't return an array from a function. You can return the address of the array but not the number of elements. So in this case, you have no idea how large the array is. In ths case, the function needs two output arguments. One for the array address and one for the number of elements. The return value should be a success/fail code.
Feb 16 '11 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Anand | last post by:
Hi i am having trouble adding a recordset into the access database, the code seems to be working fine it passs and parses through all variables just fine without showing any errors and also when i...
2
by: ed | last post by:
i'm having trouble with a form. I want to be able to type in the address of the form with the data for the form items in the URL (ie: http://somesite.com/formpage.html?field1=data1&field2=data2)....
1
by: Lauren Wilson | last post by:
I'm having trouble with the Access VBA help on my installation of A2K with Dev tools. Every time I try to retrieve help for items listed in the Object Browser (and SOME other items as well),...
2
by: Jozef | last post by:
Hello, I am trying to put together a module and open a workspace on a database that has a simple password (using Access XP). This is the lin that I'm having trouble with; Set wrk =...
0
by: Jozef | last post by:
Hello, I'm having trouble with the download links on my web server. The error I'm getting is; CGI Timeout The specified CGI application exceeded the allowed time for processing. The server...
2
by: cnliou | last post by:
Linux 2.4.23 on AMD 450MHz. pgsql 7.4.1 configure --enable-multibyte=UNICODE locale is zh_TW.Big5 IIRC, when I did "initdb -E UNICODE" or "createdb db1", I saw the following message from...
5
by: Janning Vygen | last post by:
Hi, tonight my database got corruppted. before it worked fine. since two days i do the following tasks every night psql -c 'CLUSTER;' $DBNAME psql -c 'VACUUM FULL ANALYZE;' $DBNAME ...
6
by: mangesh | last post by:
1 - How to cach invalid memory access exception ? Does standard library provide any help ? 2 - Also when one write catch(...) { //........... } what is wirtten inside catch block . How do...
2
by: spidey12345 | last post by:
what i need this program to do is to read paragraphs like "st blah blh test ere se sit blha eere w" and then it will reformat to "st blah...
2
by: Stu | last post by:
Hi guys, I've been having trouble getting the clock function to work portably, please could I get some thoughts? <Possibly OT comments> It works fine on my laptop (under WinXP) and on my...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.