void RecDeal(COMM_FRAME_T frm) { ANAL_T anal = new ANAL_T(); anal = (ANAL_T)BytesToStruct(frm.data, Marshal.SizeOf(typeof(ANAL_T)), typeof(ANAL_T)); REC_ITEM rec = new REC_ITEM(); rec.img = anal.img; int i; for (i = 0; i < REC.PIX_NUM; i++) { if (rec.img[REC.LINE_SHADE1].pix[i] == 0) { rec.img[REC.LINE_SHADE1].pix[i] = 255; } else { rec.img[REC.LINE_SHADE1].pix[i] = 0; } if (rec.img[REC.LINE_SHADE2].pix[i] == 0) { rec.img[REC.LINE_SHADE2].pix[i] = 255; } else { rec.img[REC.LINE_SHADE2].pix[i] = 0; } } ShowRec(rec); }
public REC_ITEM RecFrameDeal(COMM_FRAME_T frm) { curRec = (REC_ITEM)BytesToStruct(frm.data, Marshal.SizeOf(typeof(REC_ITEM)), typeof(REC_ITEM)); //IntPtr buff = (IntPtr)(new byte[Marshal.SizeOf(typeof(REC_ITEM))]); //check record data //curRec.valid = true; //if dataerror set curRec.valid to false return(curRec); }
//Show Record void ShowRec(REC_ITEM rec) { DrawRecImg(rec); //显示记录录的图片 //显示记录中的数据 System.Text.StringBuilder sb = new System.Text.StringBuilder(); string tmp = string.Format("基准序号: {0}\r\n", rec.modelIdx); sb.Append(tmp); tmp = string.Format("判定结果 :{0:X}", rec.result); sb.Append(tmp); tmp = string.Format("判定项目 :{0:X}\r\n", rec.analEN); sb.Append(tmp); tmp = string.Format("线端位置 :最大:{0} 最小:{1} 基准:{2} 检测:{3}\r\n", rec.corePosMax * REC.PIX_SIZE, rec.corePosMin * REC.PIX_SIZE, rec.corePosStd * REC.PIX_SIZE, rec.corePos * REC.PIX_SIZE); sb.Append(tmp); tmp = string.Format("线径 :最大:{0} 最小:{1} 基准:{2} 检测:{3}\r\n", rec.coreWidthMax, rec.coreWidthMin, rec.coreWidthStd, rec.coreWidth); sb.Append(tmp); tmp = string.Format("防水栓位置 :最大:{0} 最小:{1} 基准:{2} 检测:{3}\r\n", rec.sealPosMax * REC.PIX_SIZE, rec.sealPosMin * REC.PIX_SIZE, rec.sealPosStd * REC.PIX_SIZE, rec.sealPos * REC.PIX_SIZE); sb.Append(tmp); tmp = string.Format("防水栓直径 :最大:{0} 最小:{1} 基准:{2} 检测:{3}\r\n", rec.sealWidthMax, rec.sealWidthMin, rec.sealWidthStd, rec.sealWidth); sb.Append(tmp); tmp = string.Format("剥切位置 :最大:{0} 最小:{1} 基准:{2} 检测:{3}\r\n", rec.stripPosMax * REC.PIX_SIZE, rec.stripPosMin * REC.PIX_SIZE, rec.stripPosStd * REC.PIX_SIZE, rec.stripPos * REC.PIX_SIZE); sb.Append(tmp); tmp = string.Format("剥切长度 :最大:{0} 最小:{1} 基准:{2} 检测:{3}\r\n", rec.stripLenMax * REC.PIX_SIZE, rec.stripLenMin * REC.PIX_SIZE, rec.stripLenStd * REC.PIX_SIZE, rec.stripLen * REC.PIX_SIZE); sb.Append(tmp); tmp = string.Format("分叉宽度 :最大:{0} 最小:{1} 基准:{2} 检测:{3}\r\n", rec.splayMax, rec.splayMin, rec.splayStd, rec.splay); sb.Append(tmp); if (0 != rec.isSeal) { tmp = string.Format("有无防水栓 :有\r\n"); } else { tmp = string.Format("有无防水栓 :无\r\n"); } sb.Append(tmp); tmp = string.Format("导线外径 :{0:f}\r\n", rec.refWidth); sb.Append(tmp); tmp = string.Format("缩放比例 :{0:f}\r\n", rec.yScale); sb.Append(tmp); string str = sb.ToString(); rtBox1.Text = str; }
//将记录结构体中的图片绘制到窗口 private void DrawRecImg(REC_ITEM rec) { int idx = 0; //取图片中数据计数器。图片每行128个像素,保存在4个UInt32型数据中,每个bit表示一个像素。每取一行数据,idx加4,指向下一行 uint w = rec.size.x; //图片宽度 = 128 uint h = rec.size.y; //图片高度 = 80 int x, y; Bitmap bmpOrg = new Bitmap(REC.PIX_NUM, REC.IMG_HEIGHT); //保存记录中的原始图片。显示在界面上的图片是经过放大后的,保存在bmp中 for (y = 0; y < h; y++) //循环读取每一行 { int[] line = new int[w]; //保存一行数据。将一行中每个像素展开,保存到line[]中 int cnt = 0; //行内像素计数器,line[cnt] //从记录中取一行数据 UInt32[] data = new UInt32[4]; //保存一行数据 for (int i = 0; i < 4; i++) { data[i] = rec.img[i + idx]; } idx += 4; //指向下一行数据 //将4个UInt32型数据展开到128个数据的数组line[],表示一行数据 for (int i = 0; i < 4; i++) { for (int j = 0; j < 32; j++) { if ((data[i] & 0x00000001) != 0) { line[cnt] = 1; } else { line[cnt] = 0; } data[i] >>= 1; cnt++; } } //将这一行数据写入到bmpOrg中的第y行 for (x = 0; x < w; x++) { if (0 == line[x]) { bmpOrg.SetPixel(x, y, Color.White); } else { bmpOrg.SetPixel(x, y, Color.Green); } } } //scale img int xs, ys, xd, yd; //xs ys 源图宽高 xd yd 目标图宽高 int ydOffset = (imgHeight - y * imgScaleY) / 2; //图片纵向居中 for (yd = 0; yd < imgHeight; yd++) { for (xd = 0; xd < imgWidth; xd++) { xs = xd / imgScaleX; //源图中x ys = yd / imgScaleY; //源图中y if (ys >= bmpOrg.Height) { break; } Color clr = bmpOrg.GetPixel(xs, ys); //获取源图中像素 bmp.SetPixel(xd, yd + ydOffset, clr); //填充到目标图中 } } pictureBox1.Image = bmp; //将放大后的图片显示到界面 }
//Show Record void ShowRec(REC_ITEM rec) { DrawRecImg(rec); //显示记录录的图片 }
//将记录结构体中的图片绘制到窗口 private void DrawRecImg(REC_ITEM rec) { int w = REC.PIX_NUM; //图片宽度 = 216 * 3 int x, y; //Bitmap bmpOrg = new Bitmap(REC.PIX_NUM, REC.IMG_HEIGHT); //保存记录中的原始图片。显示在界面上的图片是经过放大后的,保存在bmp中 int h1 = 50; int h2 = 150; int h3 = 200; int h4 = 250; int h5 = 300; const int shadeThresh = 50; //shade1 y = 0; for (x = 0; x < w; x++) { bmp.SetPixel(x, y, Color.FromArgb(rec.img[0].pix[x], rec.img[0].pix[x], rec.img[0].pix[x])); } for (; y < h1; y++) { for (x = 0; x < w; x++) { bmp.SetPixel(x, y, bmp.GetPixel(x, 0)); } } //color for (x = 0; x < w; x++) { bmp.SetPixel(x, y, Color.FromArgb(rec.img[1].pix[x], rec.img[2].pix[x], rec.img[3].pix[x])); } for (; y < h2; y++) { for (x = 0; x < w; x++) { bmp.SetPixel(x, y, bmp.GetPixel(x, h1)); } } //shade2 for (x = 0; x < w; x++) { bmp.SetPixel(x, y, Color.FromArgb(rec.img[4].pix[x], rec.img[4].pix[x], rec.img[4].pix[x])); } for (; y < h3; y++) { for (x = 0; x < w; x++) { bmp.SetPixel(x, y, bmp.GetPixel(x, h2)); } } pictureBox1.Image = bmp; //将放大后的图片显示到界面 //画RGB曲线 UInt16[] line = new UInt16[REC.PIX_NUM]; int i; Graphics grfx = pBoxWaveR.CreateGraphics(); int picHeight = pBoxWaveR.Height; Pen pen = new Pen(Color.Blue, 1); Point[] pts = new Point[REC.PIX_NUM]; //R for (i = 0; i < REC.PIX_NUM; i++) { pts[i].X = i; if (rec.img[0].pix[i] < shadeThresh) { pts[i].Y = picHeight - rec.img[1].pix[i] / 2; } else { pts[i].Y = picHeight - 1; } } grfx.Clear(Color.White); grfx.DrawLines(pen, pts); //G grfx = pBoxWaveG.CreateGraphics(); for (i = 0; i < REC.PIX_NUM; i++) { pts[i].X = i; if (rec.img[0].pix[i] < shadeThresh) { pts[i].Y = picHeight - rec.img[2].pix[i] / 2; } else { pts[i].Y = picHeight - 1; } } grfx.Clear(Color.White); grfx.DrawLines(pen, pts); //B grfx = pBoxWaveB.CreateGraphics(); for (i = 0; i < REC.PIX_NUM; i++) { pts[i].X = i; if (rec.img[0].pix[i] < shadeThresh) { pts[i].Y = picHeight - rec.img[3].pix[i] / 2; } else { pts[i].Y = picHeight - 1; } } grfx.Clear(Color.White); grfx.DrawLines(pen, pts); //RGB grfx = pBoxWave.CreateGraphics(); for (i = 0; i < REC.PIX_NUM; i++) { pts[i].X = i; if (rec.img[0].pix[i] < shadeThresh) { pts[i].Y = picHeight - 1 - clrDistance(Color.FromArgb(255, rec.img[1].pix[i], rec.img[2].pix[i], rec.img[3].pix[i]), Color.Black); } else { pts[i].Y = picHeight - 1; } } grfx.Clear(Color.White); grfx.DrawLines(pen, pts); grfx.Dispose(); }