public void _regist_exec(HVCP2Api hvc_p2_api) { var out_register_image = new GrayscaleImage(); var ret = hvc_p2_api.register_data(0, 0, out_register_image); if (ret == p2def.RESPONSE_CODE_NORMAL) { this.SetText(" Success to register. user_id=0 data_id=0"); this.SetText(Environment.NewLine); out_register_image.save("registerd_img.jpg"); } else if (ret == p2def.RESPONSE_CODE_NO_FACE) { this.SetText(" Number of faces that can be registered is 0."); this.SetText(Environment.NewLine); } else if (ret == p2def.RESPONSE_CODE_PLURAL_FACE) { this.SetText(" Number of detected faces is 2 or more."); this.SetText(Environment.NewLine); } else { // error this.SetText(" Error: Invalid register album. "); this.SetText(Environment.NewLine); } }
public bool _check_connection(HVCP2Api hvc_p2_api, out HVCP2Wrapper.GET_VERSION_RET result) { HVCP2Wrapper.GET_VERSION_RET ret = hvc_p2_api.get_version(); result = ret; if ((ret.response_code != 0) || (ret.hvc_type.IndexOf("B5T-007001") != 0)) { this.SetText("Error: connection failure."); this.SetText(Environment.NewLine); return(false); } else { return(true); } }
public void _set_hvc_p2_parameters(HVCP2Api hvc_p2_api) { // Sets camera angle var res_code = hvc_p2_api.set_camera_angle(hvc_camera_angle); if (res_code != p2def.RESPONSE_CODE_NORMAL) { this.SetText("Error: Invalid camera angle."); this.SetText(Environment.NewLine); return; } // Sets threshold res_code = hvc_p2_api.set_threshold(body_thresh, hand_thresh, face_thresh, recognition_thresh); if (res_code != p2def.RESPONSE_CODE_NORMAL) { this.SetText("Error: Invalid threshold."); this.SetText(Environment.NewLine); return; } // Sets detection size res_code = hvc_p2_api.set_detection_size(min_body_size, max_body_size, min_hand_size, max_hand_size, min_face_size, max_face_size); if (res_code != p2def.RESPONSE_CODE_NORMAL) { this.SetText("Error: Invalid detection size."); this.SetText(Environment.NewLine); return; } // Sets face angle res_code = hvc_p2_api.set_face_angle(face_angle_yaw, face_angle_roll); if (res_code != p2def.RESPONSE_CODE_NORMAL) { this.SetText("Error: Invalid face angle."); this.SetText(Environment.NewLine); return; } }
public void mainloop() { var hvc_tracking_result = new HVCTrackingResult(); var img = new GrayscaleImage(); HVCP2Api.EXECUTE_RET exec_ret; var sw = new Stopwatch(); while (true) { try { if (this.isConnectRequest) { var connector = new SerialConnector(); var exec_func = 0x00; if (BodyDetectionCheck.Checked == true) { exec_func += p2def.EX_BODY; } if (HandDetectionCheck.Checked == true) { exec_func += p2def.EX_HAND; } if (FaceDetectionCheck.Checked == true) { exec_func += p2def.EX_FACE; } if (FaceDirectionCheck.Checked == true) { exec_func += p2def.EX_DIRECTION; } if (AgeDetectionCheck.Checked == true) { exec_func += p2def.EX_AGE; } if (GenderDetectionCheck.Checked == true) { exec_func += p2def.EX_GENDER; } if (GazeDetectionCheck.Checked == true) { exec_func += p2def.EX_GAZE; } if (BlinkDetectionCheck.Checked == true) { exec_func += p2def.EX_BLINK; } if (ExpressionDetectionCheck.Checked == true) { exec_func += p2def.EX_EXPRESSION; } if (RecognitionDetectionCheck.Checked == true) { exec_func += p2def.EX_RECOGNITION; } this.hvc_p2_api = new HVCP2Api(connector, exec_func, StablirizationCheck.Checked); var comnum = int.Parse(this.connect_comport.Substring(3)); var ret = this.hvc_p2_api.connect(comnum, 9600, timeout * 1000); if (ret == true) { HVCP2Wrapper.GET_VERSION_RET result; this.isConnectRequest = false; var retcode = _check_connection(this.hvc_p2_api, out result); if (retcode == true) { _get_hvc_version(result); _set_hvc_p2_parameters(this.hvc_p2_api); // Sets STB library parameters _set_stb_parameters(hvc_p2_api); this.isConnected = true; } else { this.SetToDefault(); try { this.hvc_p2_api.disconnect(); } catch { } } } } if (this.isConnected) { if (this.isRegistExecute) { _regist_exec(this.hvc_p2_api); this.SetToDefault(); try { this.hvc_p2_api.disconnect(); } catch { } } else { this.isExecuting = true; sw.Reset(); sw.Start(); exec_ret = hvc_p2_api.execute(output_img_type, hvc_tracking_result, img); sw.Stop(); this.isExecuting = false; if (output_img_type != p2def.OUT_IMG_TYPE_NONE) { img.save(img_fname); } this.SetText(string.Format(" ==== Elapsed time:{0}[msec] ====", sw.ElapsedMilliseconds)); this.SetText(Environment.NewLine); this.SetText(hvc_tracking_result.ToString()); this.SetText(Environment.NewLine); this.SetText(string.Format(" Press Stop Button to end:", sw.ElapsedMilliseconds)); this.SetText(Environment.NewLine); this.SetText(Environment.NewLine); System.Windows.Forms.Application.DoEvents(); } } if (this.isEndRequest) { try { this.hvc_p2_api.disconnect(); } catch { } break; } } catch (Exception ex) { this.SetText(string.Format("Unexpected exception : {0}", ex.Message)); this.SetText(Environment.NewLine); this.SetToDefault(); try { this.hvc_p2_api.disconnect(); } catch { } } System.Threading.Thread.Sleep(10); } }
public void _set_stb_parameters(HVCP2Api hvc_p2_api) { if (hvc_p2_api.use_stb != true) { return; } // Sets tracking retry count. var ret = hvc_p2_api.set_stb_tr_retry_count(max_retry_count); if (ret != 0) { this.SetText("Error: Invalid parameter. set_stb_tr_retry_count()."); this.SetText(Environment.NewLine); return; } // Sets steadiness parameters ret = hvc_p2_api.set_stb_tr_steadiness_param(steadiness_param_pos, steadiness_param_size); if (ret != 0) { this.SetText("Error: Invalid parameter. set_stb_tr_steadiness_param()."); this.SetText(Environment.NewLine); return; } // -- Sets STB parameters for Gender/Age estimation // Sets estimation result stabilizing threshold value ret = hvc_p2_api.set_stb_pe_threshold_use(pe_threshold_use); if (ret != 0) { this.SetText("Error: Invalid parameter. set_stb_pe_threshold_use()."); this.SetText(Environment.NewLine); return; } // Sets estimation result stabilizing angle ret = hvc_p2_api.set_stb_pe_angle_use(pe_min_UD_angle, pe_max_UD_angle, pe_min_LR_angle, pe_max_LR_angle); if (ret != 0) { this.SetText("Error: Invalid parameter. set_stb_pe_angle_use()."); this.SetText(Environment.NewLine); return; } // Sets age/gender estimation complete frame count ret = hvc_p2_api.set_stb_pe_complete_frame_count(pe_complete_frame_count); if (ret != 0) { this.SetText("Error: Invalid parameter. set_stb_pe_complete_frame_count()."); this.SetText(Environment.NewLine); return; } // -- Sets STB parameters for Recognition // Sets recognition stabilizing threshold value ret = hvc_p2_api.set_stb_fr_threshold_use(fr_threshold_use); if (ret != 0) { this.SetText("Error: Invalid parameter. set_stb_fr_threshold_use()."); this.SetText(Environment.NewLine); return; } // Sets recognition stabilizing angle ret = hvc_p2_api.set_stb_fr_angle_use(fr_min_UD_angle, fr_max_UD_angle, fr_min_LR_angle, fr_max_LR_angle); if (ret != 0) { this.SetText("Error: Invalid parameter. set_stb_fr_angle_use()."); this.SetText(Environment.NewLine); return; } // Sets recognition stabilizing complete frame count ret = hvc_p2_api.set_stb_fr_complete_frame_count(fr_complete_frame_count); if (ret != 0) { this.SetText("Error: Invalid parameter. set_stb_fr_complete_frame_count()."); this.SetText(Environment.NewLine); return; } // Sets recognition minimum account ratio ret = hvc_p2_api.set_stb_fr_min_ratio(fr_min_ratio); if (ret != 0) { this.SetText("Error: Invalid parameter. set_stb_fr_min_ratio()."); this.SetText(Environment.NewLine); return; } }