Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

Why is image to array (vision call in C++) not then displaying my array in my code?

Hi Kari,
 
You are trying to display your array by writing to cout, but your application is a GUI app, not a console app, so you don't have a console to write to.  The system call works because it actually invokes a console mode app (most likely cmd.exe) to do its work.  To display from a GUI app, you need to use a UI object.  The easiest (but least flexible) is a message box.
 
If you want to get something working quickly, consider changing your code to the following:
 
/* Display the results */
    char title[80];
    sprintf(title, "The array has %d rows and %d columns", rows, cols);
    char startOfData[512];
    startOfData[0] = '\0';
    for (row = 0; row < rows && row < 4; ++row) {
        for (col = 0; col < cols && col < 16; ++col) {
            sprintf(startOfData + strlen(startOfData), "%02X ", (unsigned char)(array[col + cols * row]));
        }
        sprintf(startOfData + strlen(startOfData), "...\n");
    }
    MessageBox(startOfData, title, MB_OK);
-Jeff
 
Message 11 of 16
(2,685 Views)
Hi Maclean,
I have both run several of the example vis that come with the package and have written my own vision vis, all of which run fine. 

Thanks,
Kari
0 Kudos
Message 12 of 16
(2,673 Views)
Hi,
Thanks so much for both of your help. Kellam, this code did work and displayed a portion of my image array.  Is there a way to set this up so it will display on a console?  I think that would be easier and we could see more of the array.  I tried changing the properties<Linker<System<Subsystem from Windows to Console, but then got these errors:

 1>msvcrtd.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
1>.\Debug\LoadImArrayCon.exe : fatal error LNK1120: 1 unresolved externals

Also, when I view my image array values in the message box, everywhere I should see a 1, I see an FF. Zero values are correctly output as 00.   When I load in a greyscale image of mine, I also get strange values like B6 AA 92 etc... Do you know why this is?

Thank you so much,
Kari
0 Kudos
Message 13 of 16
(2,672 Views)

Hi Kari,

The way I set up the example was to print the hexadecimal value of each pixel - 0 is black and FF is white.  If you want to see values from 0-1, then change the appropriate line to sprintf(startOfData + strlen(startOfData), "%f ", (unsigned char)(array[col + cols * row]) / 255.0);

What you are struggling with is trying to have an application that is both a GUI app and a console app.  When you switched the linker flag, you made a console app; however, you are using MFC for your GUI, which doesn't work unless you link to build a GUI app.

Your two best options are to (1) make a dialog box with a text control on it or (2) allocate and associate a console into your GUI app.  The MFC examples should have some examples on how to make a dialog box with a text control and how to use it.  If you want to allocate a console, I'd suggest reading http://www.halcyon.com/~ast/dload/guicon.htm

Good Luck

-Jeff

 

 

Message 14 of 16
(2,657 Views)
Do you know if it is possible to take my GUI app and make it into a DLL so that I can interface with Labview and load my image directly there?  I need to alter my image using Cpp and then load into Labview.  I have tried inserting this program into a newly-created DLL and get many errors.  Is this impossible?  Any suggestions would be greatly appreciated.  Thanks,
Kari
0 Kudos
Message 15 of 16
(2,505 Views)
Hello Kari,

We have a Developer Zone tutorial that addresses the topic of Building a DLL with Visual C++.  Please click here for a link.  You may be able to find additional resources by searching www.ni.com/support.

Best Regards,
T. McCarty
0 Kudos
Message 16 of 16
(2,486 Views)