public void TransformFromImgCVToGrayImage(Image <Gray, byte> CurrentImg) { byte[,] Graymatrix = new byte[CurrentImg.Height, CurrentImg.Width]; //byte[,] Graymatrix = new byte[CurrentImg.Width, CurrentImg.Height]; //byte[] Graymatrix = new byte[grayImage.Height * grayImage.Width]; for (int v = 0; v < CurrentImg.Height; v++) { for (int u = 0; u < CurrentImg.Width; u++) { byte a = CurrentImg.Data[v, u, 0]; //Get Pixel Color | fast way Graymatrix[v, u] = a; //Graymatrix[u, v] = a; } } E_iVision_ERRORS err2 = iImage.Resize(GrayImg, CurrentImg.Width, CurrentImg.Height); unsafe { fixed(byte *bufPointer = &Graymatrix[0, 0]) { var err = iImage.PointerToiImage(GrayImg, (IntPtr)bufPointer, CurrentImg.Width, CurrentImg.Height); if (err != E_iVision_ERRORS.E_OK) { MessageBox.Show(err.ToString(), "ERROR"); // return IntPtr.Zero; } } } }
private void button1_Click(object sender, EventArgs e) { E_iVision_ERRORS err = E_iVision_ERRORS.E_NULL; err = iMatch.iVisitingKey(); if (err != E_iVision_ERRORS.E_OK) { MessageBox.Show(err.ToString(), "Error"); label2.Text = "Error"; } else { label2.Text = "OK"; } }
private void Image_FinalStepResize(byte[,] Final_Graymatrix, int FinalWid, int FinalHei) { E_iVision_ERRORS err2 = iImage.Resize(GrayImg, FinalWid, FinalHei); unsafe { fixed(byte *bufPointer = &Final_Graymatrix[0, 0]) { err2 = iImage.PointerToiImage(GrayImg, (IntPtr)bufPointer, FinalWid, FinalHei); if (err2 != E_iVision_ERRORS.E_OK) { MessageBox.Show(err2.ToString(), "Error"); return; } hbitmap = iImage.GetBitmapAddress(GrayImg); pictureBox1.Image = System.Drawing.Image.FromHbitmap(hbitmap); pictureBox1.Refresh(); } } //txt_Buffersize.Text = Convert.ToString(buffersize); // txt_height.Text = Convert.ToString(FinalHei); // txt_width.Text = Convert.ToString(FinalWid); }//
public extern static IntPtr iGetErrorText(E_iVision_ERRORS eError);
public void btn_NCCmatching_Click(object sender, EventArgs e) { E_iVision_ERRORS err = E_iVision_ERRORS.E_NULL; UpData_NCC_Parameter(); iMatch.iSetMinScore(TheMainfrm.Matchmodel, MinScore); iMatch.iSetIsRotated(TheMainfrm.Matchmodel, UsingRotation); iMatch.iSetIsScaled(TheMainfrm.Matchmodel, UsingScale); iMatch.iSetOccurrence(TheMainfrm.Matchmodel, Max_objs); iMatch.iSetAngle(TheMainfrm.Matchmodel, MaxAng, MinAng); iMatch.iSetScale(TheMainfrm.Matchmodel, MaxScale, MinScale); iMatch.iSetDontCareThreshold(TheMainfrm.Matchmodel, DontCarevalue); iMatch.iSetRobustness(TheMainfrm.Matchmodel, UsingRobust); iMatch.iSetSubPixel(TheMainfrm.Matchmodel, UsingSubpixel); iMatch.iSetColorSimilarity(TheMainfrm.Matchmodel, UsingCS); iMatch.iSetColorSensitivity(TheMainfrm.Matchmodel, ColorSensitivy); iMatch.iSetFinalReduction(TheMainfrm.Matchmodel, FindReduction); err = iMatch.iIsPatternLearn(TheMainfrm.Matchmodel); if (err != E_iVision_ERRORS.E_TRUE) { MessageBox.Show(err.ToString(), "Error"); label2.Text = "Error"; return; } if (!TheMainfrm.m_bPause) { TheMainfrm.m_bRTMatch = !TheMainfrm.m_bRTMatch; if (TheMainfrm.m_bRTMatch) { btn_NCCmatching.Text = "Stop"; } else { btn_NCCmatching.Text = "Matching"; } return; } int findnum = 0; string[] str = new string[6]; double Execute_time = 0; dataGridView1.Rows.Clear(); TheMainfrm.pictureBox1.Refresh(); Graphics g = TheMainfrm.pictureBox1.CreateGraphics(); if (TheMainfrm.m_bColorSensor) { sw.Reset(); sw.Start(); err = iMatch.MatchNCCModel(TheMainfrm.ColorImg, TheMainfrm.Matchmodel); sw.Stop(); Execute_time = sw.ElapsedMilliseconds; } else { sw.Reset(); sw.Start(); err = iMatch.MatchNCCModel(TheMainfrm.GrayImg, TheMainfrm.Matchmodel); sw.Stop(); Execute_time = sw.ElapsedMilliseconds; } if (err != E_iVision_ERRORS.E_OK) { MessageBox.Show(err.ToString(), "Error"); label2.Text = "Error"; return; } else { label2.Text = E_iVision_ERRORS.E_OK.ToString(); } err = iMatch.iDrawiMatchResults(TheMainfrm.Matchmodel, g.GetHdc(), 1); err = iMatch.iGetNCCMatchNum(TheMainfrm.Matchmodel, ref findnum); if (err != E_iVision_ERRORS.E_OK) { MessageBox.Show(err.ToString(), "Error"); label2.Text = "Error"; return; } Execute_time /= findnum; for (int i = 0; i < findnum; i++) { err = iMatch.iGetNCCMatchResults(TheMainfrm.Matchmodel, i, ref objfind); str[0] = objfind.score.ToString("0.00"); str[1] = objfind.cp.x.ToString("0.00"); str[2] = objfind.cp.y.ToString("0.00"); str[3] = objfind.angle.ToString("0.00"); str[4] = objfind.scale.ToString("0.00"); str[5] = Execute_time.ToString("0.00"); dataGridView1.Rows.Add(str[0], str[1], str[2], str[3], str[4], str[5]); } }
public void btn_NCCtraining_Click(object sender, EventArgs e) { E_iVision_ERRORS err = E_iVision_ERRORS.E_NULL; //UpData_NCC_Parameter(); MinReduceArea = Convert.ToInt32(tbx_MinReduceArea.Text); err = iMatch.iSetMinReduceArea(TheMainfrm.Matchmodel, MinReduceArea); if (err != E_iVision_ERRORS.E_OK) { MessageBox.Show(err.ToString(), "Error"); label2.Text = "Error"; } else { label2.Text = "E_OK"; } err = iMatch.iSetDontCareThreshold(TheMainfrm.Matchmodel, DontCarevalue); if (err != E_iVision_ERRORS.E_OK) { MessageBox.Show(err.ToString(), "Error"); label2.Text = "Error"; } else { label2.Text = "E_OK"; } if (chk_TrainingFromROI.CheckState == CheckState.Checked) { iBaseROI l_rect = new iBaseROI(); double[] l_data = new double[10]; if (iROI.Size(TheMainfrm.TrainROITool) == 0) { label2.Text = "ERROR: the size of ROI is 0."; return; } l_rect = (iBaseROI)TheMainfrm.GetROIinfoByType(iROIType.BaseROI); iRect rect; rect.top = l_rect.org_y; rect.bottom = l_rect.org_y + l_rect.height; rect.left = l_rect.org_x; rect.right = l_rect.org_x + l_rect.width; if (TheMainfrm.UsingColor) { err = iMatch.CreateNCCModelFromROI(TheMainfrm.ColorImg, TheMainfrm.Matchmodel, rect, UsingMask); if (err != E_iVision_ERRORS.E_OK) { MessageBox.Show(err.ToString(), "Error"); label2.Text = "Error"; } else { label2.Text = "E_OK"; } } else { err = iMatch.CreateNCCModelFromROI(TheMainfrm.GrayImg, TheMainfrm.Matchmodel, rect, UsingMask); if (err != E_iVision_ERRORS.E_OK) { MessageBox.Show(err.ToString(), "Error"); label2.Text = "Error"; } else { label2.Text = "E_OK"; } } iROI.DeleteROI(TheMainfrm.TrainROITool); iROI.Plot(TheMainfrm.TrainROITool, TheMainfrm.hDC); } else { if (TheMainfrm.UsingColor) { err = iMatch.CreateNCCModel(TheMainfrm.ColorImg, TheMainfrm.Matchmodel, UsingMask); if (err != E_iVision_ERRORS.E_OK) { MessageBox.Show(err.ToString(), "Error"); label2.Text = "Error"; } else { label2.Text = "E_OK"; } } else { err = iMatch.CreateNCCModel(TheMainfrm.GrayImg, TheMainfrm.Matchmodel, UsingMask); if (err != E_iVision_ERRORS.E_OK) { MessageBox.Show(err.ToString(), "Error"); label2.Text = "Error"; } else { label2.Text = "E_OK"; } } } }