Skip to content

Instantly share code, notes, and snippets.

@ezod
Created May 24, 2012 18:06
Show Gist options
  • Save ezod/2783170 to your computer and use it in GitHub Desktop.
Save ezod/2783170 to your computer and use it in GitHub Desktop.
Simple HALCON (Linux) program for ICube to grab a JPEG image on SIGUSR1.
#include <signal.h>
#include "HalconC.h"
#ifndef NO_EXPORT_MAIN
int quit;
Htuple AcqHandle;
void start()
{
Htuple TTemp[100];
int i, SP = 0;
create_tuple(&AcqHandle, 0);
create_tuple_s(&TTemp[SP++],"ICube");
create_tuple_i(&TTemp[SP++],1280);
create_tuple_i(&TTemp[SP++],1024);
create_tuple_i(&TTemp[SP++],0);
create_tuple_i(&TTemp[SP++],0);
create_tuple_i(&TTemp[SP++],0);
create_tuple_i(&TTemp[SP++],0);
create_tuple_s(&TTemp[SP++],"default");
create_tuple_i(&TTemp[SP++],-1);
create_tuple_s(&TTemp[SP++],"default");
create_tuple_i(&TTemp[SP++],-1);
create_tuple_s(&TTemp[SP++],"false");
create_tuple_s(&TTemp[SP++],"default");
create_tuple_s(&TTemp[SP++],"");
create_tuple_i(&TTemp[SP++],0);
create_tuple_i(&TTemp[SP++],-1);
destroy_tuple(AcqHandle);
T_open_framegrabber(TTemp[SP-16], TTemp[SP-15], TTemp[SP-14], TTemp[SP-13], TTemp[SP-12], TTemp[SP-11], TTemp[SP-10], TTemp[SP-9], TTemp[SP-8], TTemp[SP-7], TTemp[SP-6], TTemp[SP-5], TTemp[SP-4], TTemp[SP-3], TTemp[SP-2], TTemp[SP-1], &AcqHandle);
while(SP)
destroy_tuple(TTemp[--SP]);
}
void handler(int signum)
{
if(signum == SIGUSR1)
{
Hobject Image;
gen_empty_obj(&Image);
clear_obj(Image);
T_grab_image(&Image, AcqHandle);
write_image(Image, "jpeg 85", 0, "image.jpg");
clear_obj(Image);
}
else if(signum == SIGTERM)
{
T_close_framegrabber(AcqHandle);
quit = 1;
}
}
#ifndef NO_EXPORT_APP_MAIN
int main(int argc, char * argv[])
{
struct sigaction new;
new.sa_handler = handler;
sigemptyset(&new.sa_mask);
new.sa_flags = 0;
sigaction (SIGUSR1, &new, NULL);
sigaction (SIGTERM, &new, NULL);
quit = 0;
start();
while(!quit)
pause();
return 0;
}
#endif
#endif
@ezod
Copy link
Author

ezod commented May 24, 2012

Assuming your HALCON install is the 32-bit version, and in /opt/halcon, this compiles with:

gcc -I/opt/halcon/include -L/opt/halcon/lib/x86sse2-linux2.4-gcc40 -lhalcon -lhalconc -m32 -o grab grab.c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment