LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

imaqMorphology problem

Hi,

I have a problem with a simple attached application. I am triing to solve it for two days without any success.

I tried to run on various HW: AMD Turion TL-52, AMD Athlon 64 3000+, Intel Core2Duo, Intel Pentium 4 2,4GHz.
I used: CVI 8.0 (RTE 8.1.0.271), CVI 8.0.1 (RTE 8.1.1.361), CVI 7.1 (RTE 8.1.1.361) and everytime Vision Dev Module 8.2.0 (RTE 8.2.1.94) Services (8.2.1.59)

The problem appears only in the case the CVI is opened and program is run from CVI *). Usually appears an error message (enclosed image) about General Protection on line with imaqMorphology function.

If I run both exe files (reduced_morph.exe and reduced_morph_dbg.exe) and CVI is not running the program works without General protection.

If the Structural Element is modified: rows: 1 cols: N, the program does not cause General Protection at all.

I guess the Vision library has some internal mistake.

Could you help me with this?

Lukas



*) sometimes the problem appears after changing rows of Structural Element.


Message Edited by LukasM on 11-14-2007 03:05 PM
Download All
0 Kudos
Message 1 of 17
(4,788 Views)

Hi LukasM,

I tried running your code on a computer with Vision Development Module 8.2 and CVI 8.0.1 and received the same error message as you, however, I ran the same code on my personal computer with Vision Development Module 8.5 and CVI 8.1.1 and it ran just fine with no error, so apparently it was fixed along the way.  I will do some checking and see if I can find a workaround for older versions to get you up and running, though.

Carlton
CLA
0 Kudos
Message 2 of 17
(4,749 Views)

Hello,

I did a little more testing and I am now able to run the code on the machine with CVI 8.0.1.  I believe the problem is with the image you are reading and sending to imaqMorphology.  When I got the error I was reading a JPG but saving as a BMP.  My suspicion is that either that version of CVI cannot read certain image types or it cannot read in one type and then save the result as another.  Try saving your original image as a .BMP and running the program again.

Carlton
CLA
0 Kudos
Message 3 of 17
(4,745 Views)
When you create an image must add a 2-5 pixel wide margin to run the
morphology routines.

This is the border size parameter in the imaqCreateImage (IMAQ_IMAGE_U8, 3)
function.

layosh



"LukasM" <x@no.email> wrote in message
news:1195053011530-611259@exchange.ni.com...
> Hi,I have a problem with a simple attached application. I am triing to
> solve it for two days without any success.I tried to run on various HW:
> AMD Turion TL-52, AMD Athlon 64 3000+, Intel Core2Duo, Intel Pentium 4
> 2,4GHz.I used: CVI 8.0 (RTE 8.1.0.271), CVI 8.0.1 (RTE 8.1.1.361), CVI 7.1
> (RTE 8.1.1.361) and everytime Vision Dev Module 8.2.0 (RTE 8.2.1.94)
> Services (8.2.1.59)The problem appears only in the case the CVI is opened
> and program is run from CVI *). Usually appears an error message (enclosed
> image) about General Protection on line with imaqMorphology function.If I
> run both exe files (reduced_morph.exe and reduced_morph_dbg.exe) and CVI
> is not running the program works without General protection.If the
> Structural Element is modified: rows: 1 cols: N, the program does not
> cause General Protection at all.I guess the Vision library has some
> internal mistake.Could you help me with this?Lukas*) sometimes the problem
> appears after changing rows of Structural Element.Message Edited by LukasM
> on 11-14-2007 03:05 PM
>
>
> reduced_morph1.c:
> http://forums.ni.com/attachments/ni/180/32459/2/reduced_morph1.c
>
>
> imaqMorphology1.gif:
> http://forums.ni.com/attachments/ni/180/32459/3/imaqMorphology1.gif


0 Kudos
Message 4 of 17
(4,738 Views)
Hello,

thank you for testing my application and for ideas. I will try to use new version of Vision Development Module.

Probably I do not understand the second message. I work just with BMP formats in my simple application. The original BMP is saved using Vision Development Module. Maybe one problem could be, that Vis. Dev. Module saves binary image as a 256 grey-level image (the color map has 256 colours). I did not found how to save binary image with the colour map of 2 colours.

Best regards

Lukas M.


0 Kudos
Message 5 of 17
(4,736 Views)
Hello Layosh,

thank you for message. You can see in my source-code that I set border of image even bigger than you suggest because I use bigger structural element. In the case of smaller image border appears another error message (I know it) but not "General Protection Fault".

Best regards

Lukas M.
0 Kudos
Message 6 of 17
(4,735 Views)

Hello,

Let me clarify my image type post.  I had taken a random picture (the National Instruments logo that I have attached) and named it "fname.jpg", ran your code, and got the same error you had posted.  I then renamed the picture "fname.bmp" and ran the code multiple times without an error.  I did notice in your code that in the IMAQReadFile function, you just had fname as the input, but I added the quotations and the file extention.  That may make a difference.



Message Edited by Carlton H on 11-16-2007 01:57 PM
Carlton
CLA
0 Kudos
Message 7 of 17
(4,703 Views)
Hi,

I've found the same sort of issue.  We had been using CVI8.0 with Vision8.0 under XP where everything was working fine.  We have upgraded to CVI8.5 and Vision8.5 to make use of some later features and now things aren't fine.

Basically I am working with 8-bit greyscale images that have been saved in .BMP format.  I create an image of type U8 and with a border size of 7 pixels and then read the BMP into it.  Along the way in my processing I call imaqMorphology() using a 3x3 structuring element.  When running in debug mode within CVI it stops with the error "Out of bounds pointer argument (past end of memory block)" and highlights my structuring element structure.  It doesn't crash with a release mode .exe run from outside of CVI.

At first I had my structuring element as a local variable within my function, filled it in and made the kernel field point to a local array of integers (rather than allocating memory for the brief amount of time) and then passed a pointer to it into imaqMorphology().  When this failed I tried having a local structuring element pointer that I pointed to my local structure and passed this in but it still crashed.  Then I tried mallocing the memory for the kernel and filling it in but that still crashed.  Then I tried mallocing memory for the structure itself and passing this in but it still crashed.  The only way I can stop the crash is to pass NULL in.  I have also tried increasing my border size to 100 (extreme but plenty more than needed) and still it crashes.

Any thoughts?

Leon
0 Kudos
Message 8 of 17
(4,397 Views)

Hi Leon,

Do you still get the error even when using the default syntax for a 3x3 structure as shown below?

myStructuringElement.matrixCols = 3
myStructuringElement.matrixRows = 3
myStructuringElement.hexa = FALSE
myStructuringElement.kernel = malloc(9 * sizeof(int))
myStructuringElement.kernel[0] = 1
myStructuringElement.kernel[1] = 0
myStructuringElement.kernel[2] = 1
myStructuringElement.kernel[3] = 1
myStructuringElement.kernel[4] = 0
myStructuringElement.kernel[5] = 1
myStructuringElement.kernel[6] = 1
myStructuringElement.kernel[7] = 0
myStructuringElement.kernel[8] = 1

int imaqMorphology(Image* dest, Image* source, MorphologyMethod, myStructuringElement);

Also, when you state that the program crashes every time, do you mean that you get the "out of bounds pointer" error?

Carlton
CLA
0 Kudos
Message 9 of 17
(4,340 Views)
Hi Carlton,

The following is the exact snippet of code I placed into my function where I use imaqMorphology().

    {
    StructuringElement myStructuringElement;
   
    myStructuringElement.matrixCols = 3;
    myStructuringElement.matrixRows = 3;
    myStructuringElement.hexa = FALSE;
    myStructuringElement.kernel = malloc(9 * sizeof(int));
    myStructuringElement.kernel[0] = 1;
    myStructuringElement.kernel[1] = 0;
    myStructuringElement.kernel[2] = 1;
    myStructuringElement.kernel[3] = 1;
    myStructuringElement.kernel[4] = 0;
    myStructuringElement.kernel[5] = 1;
    myStructuringElement.kernel[6] = 1;
    myStructuringElement.kernel[7] = 0;
    myStructuringElement.kernel[8] = 1;

    imaqMorphology(pWorkingImage, pWorkingImage, IMAQ_ERODE, &myStructuringElement);
    }

When I load in an image (1392x1040 8-bit greyscale .bmp image), threshold it and then go to process it I get the error:   
       
         FATAL RUN-TIME ERROR:   "stripe_proc.c", line 781, col 66, thread id 0x00000E50:   Out-of-bounds pointer argument (past end of memory block).

         
Even if I don't have the source and destination images as being the same image I still get the error.

          FATAL RUN-TIME ERROR:   "stripe_proc.c", line 785, col 63, thread id 0x00000EBC:   Out-of-bounds pointer argument (past end of memory block).

         
Is there any other information that would be of use to you?

Thanks,

Leon
0 Kudos
Message 10 of 17
(4,331 Views)