/*****************************************************************************
* example_multithreaded1.c
*****************************************************************************
*
* Project: HALCON/C
* Description: simple example program which shows how to use
* Parallel HALCON's reentrancy feature
* for multithreaded applications;
* note that this program is optimized for 2 processor machines;
* therefore, it uses two threads which perform different
* tasks of the application in parallel;
*
* under UNIX (Linux) compile this file via:
* make parallel TEST_PROG=example_multithreaded
*
* NOTE: This program can only be used with Parallel HALCON;
* thus it can only be compiled and executed on
* architectures, which are supported by Parallel HALCON!
*
* (c) 1996-2000 by MVTec Software GmbH
* www.mvtec.com
*****************************************************************************
*
* $Revision: 1.6 $
* $Date: 2003/11/10 14:52:04 $
*
*/
#ifdef WIN32
#include <windows.h>
#include <process.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#ifndef WIN32
#include <pthread.h>
#endif
#include "HalconC.h"
/*****************************************************************************/
/* Global variables: */
int result0= H_MSG_TRUE; /* result (error message) */
int result1= H_MSG_TRUE; /* result (error message) */
int result2= H_MSG_TRUE; /* result (error message) */
int result3= H_MSG_TRUE; /* result (error message) */
/*****************************************************************************/
/* extract_resistors - extract resistors (can be called as program thread) */
/*****************************************************************************/
void extract_resistors(void *pars)
{
/* input/output parameters: */
Hobject hue_colored; /* strong color image */
Hobject *resistors; /* result: resistors regions */
/* local variables: */
Hobject red_region; /* red areas as one region */
Hobject red_connect; /* red areas as single regions*/
Hobject red_large; /* large red regions */
void **parameters; /* array of par. values */
/* fetch parameters: */
parameters = (void**)pars;
hue_colored = *((Hobject*)(parameters[0]));
resistors = (Hobject*)(parameters[1]);
/* get strongly colored red regions: */
result1 = threshold (hue_colored,&red_region,10,19);
if(result1 != H_MSG_TRUE) return;
result1 = connection(red_region,&red_connect);
if(result1 != H_MSG_TRUE) return;
/* extract resistors by only accepting red regions of a specific size: */
result1 = select_shape(red_connect,&red_large,"area","and",
150.000000,99999.000000);
if(result1 != H_MSG_TRUE) return;
/* create rectangle around the extracted resistor regions: */
result1 = shape_trans(red_large,resistors,"rectangle2");
}
/*****************************************************************************/
/* extract_capacitors - extract capacitors (can be called as program thread) */
/*****************************************************************************/
void extract_capacitors(void *pars)
{
/* input/output parameters: */
Hobject hue_colored; /* strong color image */
Hobject *capacitors; /* result: capacitor regions */
/* local variables: */
Hobject blue_region; /* blue areas as one region */
Hobject blue_connect; /* blue areas as single reg.s */
Hobject blue_large; /* large blue regions */
void **parameters; /* array of par. values */
/* fetch parameters: */
parameters = (void**)pars;
hue_colored = *((Hobject*)(parameters[0]));
capacitors = (Hobject*)(parameters[2]);
/* get strongly colored red regions: */
result2 = threshold(hue_colored,&blue_region,114,137);
if(result2 != H_MSG_TRUE) return;
result2 = connection(blue_region,&blue_connect);
if(result2 != H_MSG_TRUE) return;
/* extract resistors by only accepting blue regions of a specific size: */
result2 = select_shape(blue_connect,&blue_large,"area","and",
150.000000,99999.000000);
if(result2 != H_MSG_TRUE) return;
/* create rectangle around the extracted resistor regions: */
result2 = shape_trans(blue_large,capacitors,"rectangle2");
}
/*****************************************************************************/
/* extract_r_and_c - extract resistors and capacitors (can work as thread) */
/*****************************************************************************/
void extract_r_and_c(void *pars)
{
(void)extract_resistors(pars);
(void)extract_capacitors(pars);
}
/*****************************************************************************/
/* extract_ics - extract regions of ICs and their contacts */
/*****************************************************************************/
void extract_ics(Hobject intensity, Hobject *ics, Hobject *pins)
{
Hobject dark_region; /* dark areas as one region */
Hobject dark_dilation; /* region after dilation */
Hobject dark_connect; /* dark areas as single reg.s */
Hobject dark_image; /* dark regions + img. matrix */
Hobject ic_regions; /* ic regions */
Hobject ic_dilation; /* ic regions after dilation */
Hobject search_space; /* search space */
Hobject search_space_dilation; /* search space after dilation*/
Hobject search_space_union; /* search space after union */
Hobject search_gray; /* search space incl. matrix */
Hobject mean_filtered; /* mean filtered image */
Hobject pins_raw; /* raw region of pins */
Hobject pins_connect; /* raw single regions of pins */
Hobject pins_filled; /* filled up regions of pins */
/* -------- part 1: extract ICs ----------------------------------------- */
/* get dark regions (and fill up their holes): */
result3 = threshold(intensity,&dark_region,0,50);
if(result3 != H_MSG_TRUE) return;
result3 = dilation_rectangle1(dark_region,&dark_dilation,14,14);
if(result3 != H_MSG_TRUE) return;
result3 = connection(dark_dilation,&dark_connect);
if(result3 != H_MSG_TRUE) return;
/* set dark regions as valid domain of the intensity image: */
result3 = add_channels(dark_connect,intensity,&dark_image);
if(result3 != H_MSG_TRUE) return;
/* use this adapted image for searching the dark ics: */
result3 = threshold(dark_image,&ic_regions,0,50);
if(result3 != H_MSG_TRUE) return;
/* create rectangle around the extracted resistor regions: */
result3 = shape_trans(ic_regions,ics,"rectangle2");
/* -------- part 2: extract IC contacts --------------------------------- */
/* create search space for IC contacts (small rectangles along the ICs): */
result3 = dilation_rectangle1(*ics,&ic_dilation,5,1);
if(result3 != H_MSG_TRUE) return;
result3 = difference(ic_dilation,*ics,&search_space);
if(result3 != H_MSG_TRUE) return;
result3 = dilation_rectangle1(search_space,&search_space_dilation,1