Lớp lưu ngữ nghĩa và kết quả tra cứu nghĩa từ: SemanticMap

Một phần của tài liệu Môi trường phát triển phần mềm nhúng cho các thiết bị di động (Trang 103)

SemanticMap using System; using System.Collections.Generic; using System.Text; namespace MobileDevNOMRegconition1._0.AppClasses { /// <summary>

/// Lop chua anh xa ngu nghia /// </summary>

nhúng cho các thiết bị di động {

/// <summary> /// So ky tu toi da /// </summary>

public static int MaxOfCharacters = 65355;

/// <summary>

/// Mang gia tri khoa cua tap ket qua nhan danh /// </summary>

public static int[] arKey = new int[MaxOfCharacters];

/// <summary>

/// Mang chua nghia cua cac ky tu da duoc nhan dang /// </summary>

public static String[] arResultMeanning = new String[MaxOfCharacters];

/// <summary>

/// Mang chua toan bo nghia tu /// </summary>

public static String[] arSemantic = new String[MaxOfCharacters]; }

nhúng cho các thiết bị di động B.8. Lớp tra cứu nghĩa từ: LookupSemantic

using System; using System.Collections.Generic; using System.Text; using System.IO; namespace MobileDevNOMRegconition1._0.AppClasses { /// <summary>

/// Lop chua cac ham anh xa nghu nghia: /// - Nap file ngu nghia: LoadDictionary()

/// - Tao khoa cho ky tu hien tai: CreateKeyOfAChar()

/// - Tao mang khoa cho tap ket qua nhan dang: CreateKeyArray() /// - Tra tu: LookupMeanning()

/// </summary> class LookupSemantic {

/// <summary>

/// Tao mang nghu nghia /// </summary>

/// <param name="objRS"></param>

public void LoadDictionary(StreamReader objRS) {

//for (int i = 1; i <= SemanticMap.MaxOfCharacters; i++) for (int i = 1; i <= 10; i++)

{

SemanticMap.arSemantic[i] = objRS.ReadLine(); }

}

/// <summary>

/// Ham tao mang key cho tap ket qua nhan danh /// </summary>

public void CreateKeyArray() { (adsbygoogle = window.adsbygoogle || []).push({});

nhúng cho các thiết bị di động { SemanticMap.arKey[i] = CreateKeyOfAChar(i); } } /// <summary>

/// Ham tao key cho mot ky tu /// </summary>

/// <param name="pos"></param> public int CreateKeyOfAChar(int pos) {

int val = 0;

for (int i = 0; i < NetworkConfig.NumOfOutNodes; i++) { val += (int)System.Math.Pow(2, i) * RecognitionProcessResult.arOutputSet[pos, i]; } return val; } /// <summary>

/// Ham tra nghia cua tu va dat vao mang nghia cua ket qua nhan dang /// </summary>

public void LookupMeanning() {

for (int i = 0; i < MobileInputResult.NumOfCharacters; i++) { SemanticMap.arResultMeanning[i] = SemanticMap.arSemantic[SemanticMap.arKey[i]]; } } } }

nhúng cho các thiết bị di động

PHỤ LỤC C. Mã nguồn các phương thức cơ bản gói Desktop

/// <summary> /// Ham nap anh mau /// </summary>

public void load_image() {

openFileDialog1.Filter = "Bitmap Image (*.bmp)|*.bmp" ; if(openFileDialog1.ShowDialog() == DialogResult.OK) {

System.IO.StreamReader image_file_stream = new System.IO.StreamReader(openFileDialog1.FileName);

input_image=new Bitmap (openFileDialog1.FileName); pictureBox1.Image =input_image; image_file_name=Path.GetFileNameWithoutExtension(openFileDialog1.Fi leName ); image_file_path=Path.GetDirectoryName(openFileDialog1.FileName); image_file_stream.Close(); input_image_height=input_image.Height; input_image_width=input_image.Width ;

//kich thuoc anh thuc lon hon khung anh -> co lai if(input_image_width > pictureBox1.Width ) pictureBox1.SizeMode= PictureBoxSizeMode.StretchImage; else pictureBox1.SizeMode= PictureBoxSizeMode.Normal; right=1; image_start_pixel_x=0; image_start_pixel_y=0; identify_lines(); current_line=0; character_present=true; character_valid=true;

nhúng cho các thiết bị di động label5.Text = "Ảnh vào : [" + image_file_name + ".bmp]";

} }

/// <summary>

/// Xac dinh ky tu tiep theo /// </summary>

public void detect_next_character() {

number_of_input_sets=1; get_next_character(); if(character_present) {

for (int i = 0; i < matrix_width; i++) for (int j = 0; j < matrix_height; j++) input_set[i * matrix_height + j, 0] = ann_input_value[i, j]; get_inputs(0); calculate_outputs(); comboBox3.Items.Clear (); comboBox3.BeginUpdate ();

//TODO Test: Tao xau ra String strResult = ""; for(int i=0;i<number_of_output_nodes;i++) { output_bit[i]=threshold(node_output[number_of_layers-1,i]); comboBox3.Items.Add ("bit["+(i).ToString()+"] " + output_bit[i].ToString ()); } try {

//Lay noi dung item co chi so tuong ung trong mang tu dien

strResult =

nhúng cho các thiết bị di động }

catch (Exception ex) {

MessageBox.Show("Đầu ra: " +

convert_bit_array_to_int(output_bit).ToString() + " Chưa đựơc huấn luyện"); } comboBox3.EndUpdate (); output_string += " " + strResult + " "; string hexadecimal=binary_to_hex(); richTextBox1.Update (); } } /// <summary> (adsbygoogle = window.adsbygoogle || []).push({});

/// Ham chuyen mang nhi phan voi trong so tang theo chi so mang thanh so nguyen /// </summary>

/// <param name="arrBit">Mang nhi phan</param> /// <returns>So tuong ung</returns>

public int convert_bit_array_to_int(int [] arrBit) {

int val=0;

for(int i=0; i<number_of_output_nodes; i++) {

val += (int)System.Math.Pow(2, i) * arrBit[i]; }

return val; }

public void get_next_character() {

image_start_pixel_x=right+2;

image_start_pixel_y=line_top[current_line]; analyze_image();

nhúng cho các thiết bị di động public void analyze_image()

{ int analyzed_line=current_line; comboBox1.Items.Clear (); comboBox2.Items.Clear (); get_character_bounds(); if(character_present) { map_character_image_pixel_matrix(); create_character_image(); map_ann_input_matrix(); } else

MessageBox.Show("Nhận dạng xong", "Nhận dạng chữ Nôm", MessageBoxButtons.OK , MessageBoxIcon.Exclamation); }

/// <summary>

/// Ham xac dinh toa do cac dong /// </summary>

public void identify_lines() { int y=image_start_pixel_y; int x=image_start_pixel_x; bool no_black_pixel; int line_number=0; line_present=true; //thu try - catch try

{

while (line_present) {

x = image_start_pixel_x;

while (CompareColorWithWhite(input_image.GetPixel(x, y)) == 1)

nhúng cho các thiết bị di động x++; if (x == input_image_width) { x = image_start_pixel_x; y++; } if (y >= input_image_height) { line_present = false; break; } }

//xac dinh cac top va bottom cua dong hien tai if (line_present)

{ //top

line_top[line_number] = y; no_black_pixel = false;

while (no_black_pixel == false) { y++; no_black_pixel = true; for (x = image_start_pixel_x; x < input_image_width; x++) if (CompareColorWithWhite(input_image.G etPixel(x, y)) == 1) { no_black_pixel = false; } } //bottom line_bottom[line_number] = y - 1; line_number++; }

nhúng cho các thiết bị di động }

catch (Exception ex) { MessageBox.Show("Test x, y: " + x.ToString() + " - " + y.ToString()); } number_of_lines=line_number; }

Một phần của tài liệu Môi trường phát triển phần mềm nhúng cho các thiết bị di động (Trang 103)