Home > Net >  C # joint halcon achieve ROI drawing
C # joint halcon achieve ROI drawing

Time:09-17

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
Using HalconDotNet;
Using System. The Threading;

The namespace Demo
{
Public partial class Form1: Form
{
Private HTuple WindowID;
Private HObject Image;

//store image array
Private HObject [] ImageArrary=new HObject [8].

//thread object
Private Thread ThreadObject;//normal test thread

//thread to stop tag
Private bool Thread_Stop=false;//normal test thread to stop tag

Public _click ()
{
InitializeComponent();

Image=new HObject ();

CreateHalconWindow ();

LoadBatchImage ();

//LoadImage ();
ThreadObject=new Thread (new ThreadStart (PlayThread));
}

//thread function
Public void PlayThread ()
{
int i=0;
Thread_Stop=false;
HTuple width=null, height=null;
while (! Thread_Stop)
{

HOperatorSet. DispObj (ImageArrary [I], WindowID);

//get image size
HOperatorSet. GetImageSize (ImageArrary [I], out width, out height);


//by changing the image zoom to fit in the window of the normal image display
HOperatorSet. SetPart (WindowID, 0, 0, height, width);

Thread.sleep (100);

i++;

If (I & gt;=8)
{
I=0;
}
}

}

//bulk loading images
Public void LoadBatchImage ()
{
for (int i=0; I & lt; 8; I++)
{
HOperatorSet. ReadImage (out ImageArrary [I], i.T oString () + ". BMP ");

}
}

Public void CreateHalconWindow ()
{
HTuple FatherWindow=this. DisplayVideo_pictureBox. Handle;

//set the background color of the window
HOperatorSet. SetWindowAttr (" background_color ", "green");

HOperatorSet. OpenWindow (0, 0, this. DisplayVideo_pictureBox. Width, enclosing DisplayVideo_pictureBox. Height, FatherWindow, "visible", "", the out WindowID);


}

Public void LoadImage ()
{
//read an image
HOperatorSet. ReadImage (out Image, "1. BMP");

HTuple width=null, height=null;

//get image size
HOperatorSet. GetImageSize (Image, out width, out height);

//set the color of the object according to
HOperatorSet. SetColor (WindowID, "yellow");

//by changing the image zoom to fit in the window of the normal image display
HOperatorSet. SetPart (WindowID, 0, 0, height, width);

//on the window display images
HOperatorSet. DispObj (Image, WindowID);


}

Private void Start_button_Click (object sender, EventArgs e)
{
//open the normal test thread
If (ThreadObject. ThreadState==System. The Threading. ThreadState. Unstarted)
{
ThreadObject. Start ();

}

If ((ThreadObject ThreadState==System. Threading. ThreadState. Stopped) | | (ThreadObject. ThreadState==System. The Threading. ThreadState. Aborted))
{
ThreadObject=new Thread (new ThreadStart (PlayThread));
ThreadObject. Start ();

}

}

Private void Stop_button_Click (object sender, EventArgs e)
{
Thread_Stop=true;
}


Private void DrawCircle_button_Click (object sender, EventArgs e)
{
//Local iconic variables

HObject ho_Image ho_Circle;

//Local control variables Local variable
HTuple hv_NewRow=null, hv_NewColumn=null, hv_NewRadius=null;
//Initialize the local and the output iconic variables initialized local variables and output icon
HOperatorSet. GenEmptyObj (out ho_Image);
HOperatorSet. GenEmptyObj (out ho_Circle);



//set the color display object
HOperatorSet. SetColor (WindowID, "red");


//set the area filling mode to filling edge margin
HOperatorSet. SetDraw (WindowID, "margin");



//create a circular ROI
HOperatorSet. Methods like DrawCircle (WindowID out hv_NewRow, out hv_NewColumn, out hv_NewRadius);

//generates a round
Ho_Circle. The Dispose ();
HOperatorSet. GenCircle (out ho_Circle hv_NewRow, hv_NewColumn, hv_NewRadius);

//show round
HOperatorSet. DispObj (ho_Circle WindowID);

ho_Image.Dispose();
Ho_Circle. The Dispose ();
}

Private void Exit_button_Click (object sender, EventArgs e)
{
Enclosing the Close ();
}


}


}
  •  Tags:  
  • C#
  • Related