04-24-2018 03:29 AM
Hello,
I would like to make a modification on the code c that generates vision assistant under labwindowscvi the code of base allows to select a photo, I would like to use a table which allows to select several photos automatiquelly on folder and to pass them as argument in the function IVA_ProcessImage (image) Please find the code base code modify and the project to better understand thanks for your help:
Basic code:
nt main (int argc, char *argv[])
{
..........................
char** imagePath; // Image Path
int cancelled;
ImageType imageType; // Image Type
Image* image; // Image
/.................
// Display the Load Image dialog
imagePath = imaqLoadImagePopup(NULL, "*.*", NULL, "Open Image", FALSE, IMAQ_BUTTON_LOAD, 0, 0, 1, 0, &cancelled, NULL);
if (!cancelled)
{
// Get the type of the image file to create an image of the right type
imaqGetFileInfo(imagePath[0], NULL, NULL, NULL, NULL, NULL, &imageType);
// Create an IMAQ Vision image
image = imaqCreateImage(imageType, 7);
// Read the image from disk
imaqReadFile(image, imagePath[0], NULL, NULL);
// Vision Assistant Algorithm
success = IVA_ProcessImage(image);
if (!success)
err = imaqGetLastError();
// Display the image
imaqMoveWindow(DISPLAY_WINDOW, imaqMakePoint(0,0));
imaqSetWindowPalette(DISPLAY_WINDOW, IMAQ_PALETTE_BINARY, NULL, 0);
imaqDisplayImage(image, DISPLAY_WINDOW, TRUE);
// Wait for a key press before exiting
printf ("Press Enter to exit.\n");
getchar();
// Dispose resources
imaqDispose(image);
}
imaqDispose(imagePath);
return 0;
}
CODE modified :
//==============================================================================
// Includes
//==============================================================================
#include <stdio.h>
#include <nivision.h>
#include "ImageProcessing.h"
//==============================================================================
// Defines
//==============================================================================
#define DISPLAY_WINDOW 0
int currentImage = 0;
#define NUM_OCR_IMAGES 9
//==============================================================================
// Main Function
//==============================================================================
int main (int argc, char *argv[])
{ int i;
int success = 1;
int err = 0;
char** imagePath; // Image Path
int cancelled;
ImageType imageType; // Image Type
Image* ocrImagesArray[NUM_OCR_IMAGES]; // Image
// IMAQ Vision creates windows in a separate thread
imaqSetWindowThreadPolicy(IMAQ_SEPARATE_THREAD);
//// Display the Load Image dialog
//imagePath = imaqLoadImagePopup(NULL, "*.*", NULL, "Open Image", FALSE, IMAQ_BUTTON_LOAD, 0, 0, 1, 0, &cancelled, NULL);
//if (!cancelled)
//{
//// Get the type of the image file to create an image of the right type
//imaqGetFileInfo(imagePath[0], NULL, NULL, NULL, NULL, NULL, &imageType);
for ( i = 0; i < NUM_OCR_IMAGES; i++ )
ocrImagesArray[i] = imaqCreateImage (IMAQ_IMAGE_U8, 10);
/* Load all the OCR images */
imaqReadFile( ocrImagesArray[0], "OCR\\Image 00.bmp", NULL, NULL);
imaqReadFile( ocrImagesArray[1], "OCR\\Image 01.bmp", NULL, NULL);
imaqReadFile( ocrImagesArray[2], "OCR\\Image 02.bmp", NULL, NULL);
imaqReadFile( ocrImagesArray[3], "OCR\\Image 03.bmp", NULL, NULL);
imaqReadFile( ocrImagesArray[4], "OCR\\Image 04.bmp", NULL, NULL);
imaqReadFile( ocrImagesArray[5], "OCR\\Image 05.bmp", NULL, NULL);
imaqReadFile( ocrImagesArray[6], "OCR\\Image 06.bmp", NULL, NULL);
imaqReadFile( ocrImagesArray[7], "OCR\\Image 07.bmp", NULL, NULL);
imaqReadFile( ocrImagesArray[8], "OCR\\Image 08.bmp", NULL, NULL);
// // Create an IMAQ Vision image
//ocrImagesArray[i] = imaqCreateImage(imageType, 7);
// // Read the image from disk
// imaqReadFile(image, imagePath[0], NULL, NULL);
// Vision Assistant Algorithm
success = IVA_ProcessImage(ocrImagesArray[i]);
if (!success)
err = imaqGetLastError();
// Display the image
imaqMoveWindow(DISPLAY_WINDOW, imaqMakePoint(0,0));
imaqSetWindowPalette(DISPLAY_WINDOW, IMAQ_PALETTE_BINARY, NULL, 0);
imaqDisplayImage(ocrImagesArray[i], DISPLAY_WINDOW, TRUE);
// Wait for a key press before exiting
printf ("Press Enter to exit.\n");
getchar();
// Dispose resources
for ( i = 0; i < NUM_OCR_IMAGES; i++ )
imaqDispose(ocrImagesArray[i]);
return 0;
}
ERROOR
FATAL RUN-TIME ERROR: "Main.c", line 77, col 36, thread id 10448: Dereference of out-of-bounds pointer: 1 bytes (1 elements) past end of array.