PDA

View Full Version : Use C or PERL with ActiveX control example



sapbucket
December 17, 2004, 07:43:37
This post is intented to help anyone who wants to undertake using the ICImagingControl from other programming languages besides VB.NET, C#, or C++.

Please see other posts with 'sapbucket' as the thread starter to get an IN-DEPTH look at how the following was developed. I give thanks to Stefan Geissler and ozo at www.experts-exchange.com for their generous assistance in helping me develop the following PERL solution:




#!/usr/bin/perl -w

#--------------------------------
# start of profiler:
# start section
use Time::HiRes qw( usleep ualarm gettimeofday tv_interval );
$t0 = [gettimeofday];
# end section
#--------------------------------


#--------------------------------
# instance an imaging control using Win32::OLE:
# start section:
use Win32::OLE;
$imaging = Win32::OLE->new('IC.ICImagingControl') or die "oops\n";
# end section
#--------------------------------


#--------------------------------
# Use the Dialog to get camera settings:
# start section
# If we want to change settings we need to use the dialog and and save
# the state so we can load from file.
#$imaging->ShowDeviceSettingsDialog();
#$imaging->SaveDeviceStateToFile("c:\\ocr\\device_state.xml");
# end section
#--------------------------------

#---------------------------------
# This section is used by all following sections.
# start section
$imaging->LoadDeviceStateFromFile("c:\\ocr\\device_state.xml",1);
$imaging->MemorySnapImage();
$imaging->MemorySaveImage("c:\\ocr\\test1.bmp");
$buffer = $imaging->ImageBuffers->Item(1);
# end section
#---------------------------------


#-------------------------------------------
# This section tries to use ImageDataPtr() to access image data.
# Hopefully it will not interfere with saving the image.
# start section
$ptrData=$buffer->ImageDataPtr();
print "ptrData prior to muck() is $ptrData\n";
$indexForImage = 640*480*3; # HARDCODED!!!! BEWARE CHANGES TO HARDWARE SETTINGS
for($i=0;$i<$indexForImage; $i++) {
muck($ptrData); # will print output from muck...
$ptrData++;
}
$imaging->MemorySaveImage("c:\\ocr\\test2.bmp"); # nope! saves great!!!
# end section
#-------------------------------------------

#-------------------------------------------
# second half of profiler:
# start section
print $imaging->ImageWidth();print ", ";
print $imaging->ImageHeight();print "\n";
($seconds, $microseconds) = gettimeofday;
$elapsed = tv_interval ( $t0, [$seconds, $microseconds]);
print "elapsed time is $elapsed s\n";
# end section
#-------------------------------------------


use Inline C;
__END__
__C__

void muck(long memory_address) {
// convert using a type cast:
unsigned char* Adr = (unsigned char*)memory_address;
// perform some type of image processing:
*Adr = 255 - (*Adr);
// uncomment the following to see process from command line:
// remember to use %ld, NOT %l!!!!
//printf("Hello long: %ld!\n", memory_address);
//printf("Hello address: %ld\n", Adr);
//printf("Hello address contents: %ld\n", *Adr);

}




While the above may seem unassuming it works VERY well and FAST.

Pat-on-the-back sapbucket...