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 -
CvCapture * Capture=NULL;
-
Capture = cvCaptureFromCAM(-1);
-
-
IplImage* FrameImage = 0;
-
IplImage* MirrorImage = 0;
-
-
for(;;)
-
{
-
FrameImage = cvQueryFrame(Capture);
-
-
MirrorImage = cvCloneImage(FrameImage);
-
cvFlip(MirrorImage, NULL, 1);
-
-
int b, r, g; //colour channels
-
int x, y; //For indexing through image
-
-
cvNamedWindow( "OutPut", CV_WINDOW_AUTOSIZE );
-
-
for ( x = 0; x < MirrorImage->width; x++ )
-
{
-
for ( y = 0; y < MirrorImage->height; y++ )
-
{
-
b = ((uchar *)(MirrorImage->imageData + x*MirrorImage->widthStep))[y*MirrorImage->nChannels+0];
-
g = ((uchar *)(MirrorImage->imageData + x*MirrorImage->widthStep))[y*MirrorImage->nChannels+1];
-
r = ((uchar *)(MirrorImage->imageData + x*MirrorImage->widthStep))[y*MirrorImage->nChannels+2];
-
-
if ( !( g > 170 && r < 150 && b < 150 ) )
-
{
-
(FrameImage->imageData + x*FrameImage->widthStep)[y*FrameImage->nChannels+0]=(MirrorImage->imageData + x*MirrorImage->widthStep)[y*MirrorImage->nChannels+0];
-
(FrameImage->imageData + x*FrameImage->widthStep)[y*FrameImage->nChannels+1]=(MirrorImage->imageData + x*MirrorImage->widthStep)[y*MirrorImage->nChannels+1];
-
(FrameImage->imageData + x*FrameImage->widthStep)[y*FrameImage->nChannels+2]=(MirrorImage->imageData + x*MirrorImage->widthStep)[y*MirrorImage->nChannels+2];
-
}
-
}
-
}
-
cvShowImage(WinName, FinImage);
-
cvShowImage("OutPut", FrameImage);
-
}
-
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.
4 2297
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.
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
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.
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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)....
|
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),...
|
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 =...
|
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...
|
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...
|
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
...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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,...
|
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...
| |