Halcon10-C語言圖像處理2
#include "HalconC.h"
main()
{
? Hobject? ?Horse,Sobel,Seg,Skel;
? Htuple? ? paint_mode,luts;
? int? ? ? ?i,num;
? double? ? Threshold;
? Hobject? ?Reg,Liste;
? long? ? ? WindowHandle;
? long? ? ? Pointer,Width,Height;
? char? ? ? Type[MAX_STRING];
? Htuple? ? WindowHandleTuple;
? (void)printf("Read image <horses>\n");
? if (read_image(&Horse,"horses") != H_MSG_TRUE)
? {
? ? (void)printf("Could not find or open file <horses>\n");
? ? (void)printf("Specify HALCONIMAGES to the image directory\n");
? ? return(1);
? }??
? (void)get_image_pointer1(Horse,&Pointer,Type,&Width,&Height);
? (void)open_window(0,0,Width,Height,0,"visible","",&WindowHandle);
? (void)set_part(WindowHandle,0,0,Height-1,Width-1);
? create_tuple(&WindowHandleTuple,1);
? set_i(WindowHandleTuple,WindowHandle,0);
? (void)disp_image(Horse,WindowHandle);
? (void)printf("-> To continue: Click with mouse in graphics window ...\n");
? (void)get_mbutton(WindowHandle,_,_,_);? ?/* anonymous variable */
??
? (void)printf("Edge filter (sobel)\n");
? (void)sobel_amp(Horse,&Sobel,"sum_abs",3);
? (void)disp_image(Sobel,WindowHandle);
? (void)printf("-> To continue: Click with mouse in graphics window ...\n");
? (void)get_mbutton(WindowHandle,_,_,_);
??
? /* display LUTs */
? (void)printf("Query all available LUTs:\n");
? (void)T_query_lut(WindowHandleTuple,&luts);
? num = length_tuple(luts);
? if (num <= 1)
? ? (void)printf("-> No LUTs available!\n");
? else
? {
? ? for (i=1; i<num; i++)? /* ignore first LUT (default) */
? ? {
? ? ? (void)printf("-> Using LUT <%s> ... ",get_s(luts,i));?
? ? ? (void)set_lut(WindowHandle,get_s(luts,i));
? ? ? /* redisplay for 24 bit displays ... */
? ? ? (void)disp_image(Sobel,WindowHandle);
? ? ? (void)printf("continue: click with mouse\n");
? ? ? (void)get_mbutton(WindowHandle,_,_,_);??
? ? }
? ? (void)set_lut(WindowHandle,"default");? ?/* set LUT back */
? }
? destroy_tuple(luts);
??
? (void)printf("Display histogram of sobel image\n");
? (void)disp_image(Sobel,WindowHandle);
? create_tuple(&paint_mode,4);
? set_s(paint_mode,"histogram",0);
? set_i(paint_mode,150,1);? ? ?/* center of gravity (row) */
? set_i(paint_mode,150,2);? ? ?/* center of gravity (column) */
? set_i(paint_mode,2,3);? ? ? ?/* size */
? (void)T_set_paint(WindowHandleTuple,paint_mode);
? (void)set_draw(WindowHandle,"margin");
? (void)set_color(WindowHandle,"red");
? (void)disp_image(Sobel,WindowHandle);
? destroy_tuple(paint_mode);
? create_tuple(&paint_mode,1);
? set_s(paint_mode,"default",0); /* back to original paint mode */
? (void)T_set_paint(WindowHandleTuple,paint_mode);
? destroy_tuple(paint_mode);
? (void)printf("-> To continue: Click with mouse in graphics window ...\n");
? (void)get_mbutton(WindowHandle,_,_,_);??
??
? (void)printf("Segmentation\n");
? (void)min_max_gray(Sobel,Sobel,20.0,_d,&Threshold,_d);
? (void)printf("-> Used thresholds: %f %f\n",Threshold,255.0);
? (void)threshold(Sobel,&Seg,Threshold,255.0);
? (void)clear_window(WindowHandle);
? (void)set_draw(WindowHandle,"fill");
? (void)disp_region(Seg,WindowHandle);
? (void)printf("-> To continue: Click with mouse in graphics window ...\n");
? (void)get_mbutton(WindowHandle,_,_,_);? ?
??
? (void)printf("Calculation of skeleton\n");
? (void)skeleton(Seg,&Skel);
? (void)set_color(WindowHandle,"blue");
? (void)disp_region(Skel,WindowHandle);
? (void)printf("-> To continue: Click with mouse in graphics window ...\n");
? (void)get_mbutton(WindowHandle,_,_,_);
? (void)disp_image(Horse,WindowHandle);
? (void)set_color(WindowHandle,"red");
? (void)disp_region(Skel,WindowHandle);
? (void)printf("-> To continue: Click with mouse in graphics window ...\n");
? (void)get_mbutton(WindowHandle,_,_,_);
? (void)clear_obj(Skel);
?
? (void)printf("Regions between edges\n");
? (void)complement(Seg,&Reg);
? (void)connection(Reg,&Liste);
? (void)set_colored(WindowHandle,12);
? (void)clear_window(WindowHandle);
? (void)disp_region(Liste,WindowHandle);
? (void)printf("-> To continue: Click with mouse in graphics window ...\n");
? (void)get_mbutton(WindowHandle,_,_,_);
? (void)clear_obj(Sobel);
? (void)clear_obj(Seg);
? (void)clear_obj(Reg);
? (void)clear_obj(Liste);
??
? (void)printf("Regiongrowing\n");
? (void)regiongrowing(Horse,&Seg,2,2,20.0,200);
? (void)set_colored(WindowHandle,12);
? (void)clear_window(WindowHandle);
? (void)disp_region(Seg,WindowHandle);
? (void)printf("-> To continue: Click with mouse in graphics window ...\n");
? (void)get_mbutton(WindowHandle,_,_,_);
? (void)disp_image(Horse,WindowHandle);
? (void)set_draw(WindowHandle,"margin");
? (void)disp_region(Seg,WindowHandle);
? (void)printf("-> To continue: Click with mouse in graphics window ...\n");
? (void)get_mbutton(WindowHandle,_,_,_);
? (void)clear_obj(Seg);
? (void)clear_obj(Horse);? ?/* an' always tidy up yer room */
??
? (void)printf("The End.\n");
? return(0);
}