//跳点去震动函数:piontsWithVibrationcorrection() public void piontsWithVibrationcorrection(OpticMeasureClass opticFlowFunc) { int PointArraylength; //第i张母板点坐标数组长度 int InReferencePictureIndex = 0; //在母板系照片灰度中的索引 int s = 0; //点序号 Mt = new CSharpAlgorithm.Algorithm.MatrixOfAlgorithm(); trian = new Triangulation(); // 创建三角剖分对象 CalculateWidthAndHightOfPointImage(); //计算母板点数组的长和宽 //call装顶点表函数,装母板顶点表 trian.GetTrianglerVertexArrayFunc(ReferencePictureBitmap.Height, ReferencePictureBitmap.Width, StepValue); PointArraylength = trian.TriangleVertexArray.Length; //母板点数组长度 //PointArraylength = RefPicturePointArrayWidth * RefPicturePointArrayHight;//母板点数组长度 packedPiontImageCoorditionArrayFunction(opticFlowFunc, PointArraylength); //装载到母板点数组中 //销毁trian对象 trian = null; //可以这么销毁 functionFun.ReadMarkPointsFunc(); //call读识标记点函数,将母板的标记点识取出来 //将第i张母板标记点存到PictureOpticflowDataResultArray[ReferencePictureDataArray[i].ReferencePictureIndex].PictureMarkpointsArray opticFlowFunc.PictureOpticflowDataResultArray[opticFlowFunc.ReferencePictureDataArray[InReferencePictureDataArrayIndex].ReferencePictureIndex].PictureMarkpointsArray = functionFun.MarkPointsArray; CreatArray.creatInReferencePicturePixXYArray(RefPictureHight * RefPictureWidth, ref InReferencePicturePixXYArray); //创建像素经过旋转平移后在母板坐标系下的坐标数组 //=======匹配照片 循环计算===== for (int k = 0; k < length; k++) { CurPictureIndex = opticFlowFunc.ReferencePictureDataArray[InReferencePictureDataArrayIndex].IndexOfPictureForMachArray[k]; //待匹配照片在结果数组中的索引 CreatArray.creatPointsResultArray(opticFlowFunc, CurPictureIndex, RefPicturePointArrayHight, RefPicturePointArrayWidth); //创建点光流结果数组 CurrentPictureBitmap = (Bitmap)Image.FromFile(opticFlowFunc.PictureOpticflowDataResultArray[CurPictureIndex].PictureLujin); CreatArray.creatPictureGreyArray(CurrentPictureBitmap, ref CurrentPictureGreyArray); //创建 匹配照片灰度数组 functionFun.LoadgrayValuesArrayForMatch(CurrentPictureBitmap, ref CurrentPictureGreyArray); //装待匹配照片灰度数组 CreatArray.creatPictureDlateGreyArray(CurrentPictureBitmap, ref PictureDlateGreyArray); //创建灰度差数组 CreatArray.creatHomologousPointsDisplacementsArray(PointArraylength, ref HomologousPointsDisplacementsArray); //创建位移场数组 functionFun.ReadMarkPointsFunc(); //call识标记点函数 opticFlowFunc.PictureOpticflowDataResultArray[CurPictureIndex].PictureMarkpointsArray = functionFun.MarkPointsArray; //将第K张待匹配照片标记点到光流结果数组中 // call 求旋转平移矩阵函数,得到母板照片旋转平移到当前待匹配照片上的旋转平移矩阵函数 functionFun.GetRotationMatrixAndTranslationFunc(ref Mt); // 求母板照片和待匹配照片灰度差 for (int j = 0; j < CurrentPictureGreyArray.Length; j++) { // 得到旋转平移后的坐标 functionFun.Get2DzuobiaoInReferencePictureFunc(opticFlowFunc, CurrentPictureBitmap, Mt, T, InReferencePictureDataArrayIndex, j, CurrentPictureGreyArray.Length, ref InReferencePicturePixXYArray); //计算编号 functionFun.CalculateIndexOfInReferencePictureFunc(RefPictureHight, RefPictureWidth, j, InReferencePicturePixXYArray, ref InReferencePictureIndex); //求灰度差 直接相减 PictureDlateGreyArray[j] = CurrentPictureGreyArray[j].OrigingrayValue - ReferencePictureGreyArray[InReferencePictureIndex].OrigingrayValue; } //清数组 Array.Resize(ref CurrentPictureGreyArray, 0); //=============待匹配照片 点循环 计算(去震动)================== //for (int j = 0; j < PointArraylength; j++) //{ // //将点坐标存起 // opticFlowFunc.PictureOpticflowDataResultArray[CurPictureIndex].OpticflowResultFOfPointsArray[j].pointCoordinate.X = opticFlowFunc.ReferencePictureDataArray[i].PiontImageCoorditionArray[j].X; // opticFlowFunc.PictureOpticflowDataResultArray[CurPictureIndex].OpticflowResultFOfPointsArray[j].pointCoordinate.Y = opticFlowFunc.ReferencePictureDataArray[i].PiontImageCoorditionArray[j].Y; // // call求灰度差函数 // functionFun.racepossibleEdgePointIndexFunc(RefPicturePointArrayHight, RefPicturePointArrayWidth, opticFlowFunc.ReferencePictureDataArray[i].IndexArray[j], ref CurrentPixtNeighbourArray); // //判断 八邻域数组长度是否为8,不为8的话 梯度赋0 // if (CurrentPixtNeighbourArray.Count == 8) // { // //soble算子 // Grad.X = 1 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[1]] + 2 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[2]] + 1 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[3]] - 1 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[5]] - 2 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[6]] - 1 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[7]]; // Grad.Y = -2 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[0]] - 1 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[1]] + 1 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[3]] + 2 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[4]] + 1 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[5]] - 1 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[7]]; // } // else // { // Grad.X = 0; // Grad.Y = 0; // } // //将灰度差存到结果数组里面 // opticFlowFunc.PictureOpticflowDataResultArray[CurPictureIndex].OpticflowResultFOfPointsArray[j].Grad = Grad; //} //=====存到赵涛数组里=========== //装载显示点的坐标 for (int j = 0; j < PointArraylength; j++) { HomologousPointsDisplacementsArray[j].pointCoordinate.X = opticFlowFunc.ReferencePictureDataArray[InReferencePictureDataArrayIndex].PiontImageCoorditionArray[j].X; HomologousPointsDisplacementsArray[j].pointCoordinate.Y = opticFlowFunc.ReferencePictureDataArray[InReferencePictureDataArrayIndex].PiontImageCoorditionArray[j].Y; } //====母板点数组循环计算========= for (int j = 0; j < PointArraylength; j++) { //装八邻域数组 functionFun.racepossibleEdgePointIndexFunc(ReferencePictureBitmap.Height, ReferencePictureBitmap.Width, opticFlowFunc.ReferencePictureDataArray[InReferencePictureDataArrayIndex].IndexArray[j], ref CurrentPixtNeighbourArray); //判断 八邻域数组长度是否为8,不为8的话 梯度赋0 if (CurrentPixtNeighbourArray.Count == 8) { //soble算子 HomologousPointsDisplacementsArray[s].deltaX = 1 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[1]] + 2 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[2]] + 1 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[3]] - 1 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[5]] - 2 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[6]] - 1 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[7]]; HomologousPointsDisplacementsArray[s].deltaY = -2 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[0]] - 1 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[1]] + 1 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[3]] + 2 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[4]] + 1 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[5]] - 1 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[7]]; } else { HomologousPointsDisplacementsArray[s].deltaX = 0; HomologousPointsDisplacementsArray[s].deltaY = 0; } s++; } //销毁对象 functionFun = null; // 清除数组 Array.Resize(ref PictureDlateGreyArray, 0); CurrentPixtNeighbourArray.Clear(); } // 清除数组 Array.Resize(ref ReferencePictureGreyArray, 0); }
// 跳点不去震动函数:piontsNoVibrationcorrection() public void piontsNoVibrationcorrection(OpticMeasureClass opticFlowFunc) { int PointArraylength; //第i张母板点坐标数组长度 CalculateWidthAndHightOfPointImage(); //计算母板点数组的长和宽 trian = new Triangulation(); // 创建三角剖分对象 //call装顶点表函数,装母板顶点表 trian.GetTrianglerVertexArrayFunc(ReferencePictureBitmap.Height, ReferencePictureBitmap.Width, StepValue); PointArraylength = trian.TriangleVertexArray.Length; packedPiontImageCoorditionArrayFunction(opticFlowFunc, PointArraylength);//装母板点数组 //销毁trian对象 trian.Destroy(); GC.Collect(); //=============待匹配照片循环 计算================== for (int k = 0; k < length; k++) { CurPictureIndex = opticFlowFunc.ReferencePictureDataArray[InReferencePictureDataArrayIndex].IndexOfPictureForMachArray[k];//待匹配照片在结果数组中的索引 CurrentPictureBitmap = (Bitmap)Image.FromFile(opticFlowFunc.PictureOpticflowDataResultArray[opticFlowFunc.ReferencePictureDataArray[InReferencePictureDataArrayIndex].IndexOfPictureForMachArray[k]].PictureLujin); CreatArray.creatPictureGreyArray(CurrentPictureBitmap, ref CurrentPictureGreyArray); //创建 匹配照片灰度数组 CreatArray.creatPictureDlateGreyArray(CurrentPictureBitmap, ref PictureDlateGreyArray); //创建灰度差值数组 functionFun.LoadgrayValuesArrayForMatch(CurrentPictureBitmap, ref CurrentPictureGreyArray); //装载 匹配照片灰度数组 //CreatArray.creatHomologousPointsDisplacementsArray(PointArraylength,ref HomologousPointsDisplacementsArray);//创建位移场数组 CreatArray.creatPointsResultArray(opticFlowFunc, CurPictureIndex, RefPicturePointArrayHight, RefPicturePointArrayWidth);//创建结果数组 // 求母板照片和待匹配照片灰度差 for (int j = 0; j < CurrentPictureGreyArray.Length; j++) { PictureDlateGreyArray[j] = CurrentPictureGreyArray[j].OrigingrayValue - ReferencePictureGreyArray[j].OrigingrayValue; } //清数组 Array.Resize(ref CurrentPictureGreyArray, 0); //====母板点数组循环计算========= for (int j = 0; j < PointArraylength; j++) { //装载点坐标数组 opticFlowFunc.PictureOpticflowDataResultArray[CurPictureIndex].OpticflowResultFOfPointsArray[j].pointCoordinate.X = opticFlowFunc.ReferencePictureDataArray[InReferencePictureDataArrayIndex].PiontImageCoorditionArray[j].X; opticFlowFunc.PictureOpticflowDataResultArray[CurPictureIndex].OpticflowResultFOfPointsArray[j].pointCoordinate.Y = opticFlowFunc.ReferencePictureDataArray[InReferencePictureDataArrayIndex].PiontImageCoorditionArray[j].Y; //装八邻域数组 functionFun.racepossibleEdgePointIndexFunc(ReferencePictureBitmap.Height, ReferencePictureBitmap.Width, opticFlowFunc.ReferencePictureDataArray[InReferencePictureDataArrayIndex].IndexArray[j], ref CurrentPixtNeighbourArray); //soble算子 Grad.X = 1 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[1]] + 2 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[2]] + 1 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[3]] - 1 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[5]] - 2 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[6]] - 1 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[7]]; Grad.Y = -2 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[0]] - 1 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[1]] + 1 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[3]] + 2 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[4]] + 1 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[5]] - 1 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[7]]; //Prewitt算子 //Grad.X = 1 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[1]] + 1 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[2]] + 1 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[3]] - 1 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[5]] - 1 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[6]] - 1 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[7]]; //Grad.Y = -1 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[0]] - 1 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[1]] + 1 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[3]] +1 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[4]] + 1 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[5]] - 1 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[7]]; opticFlowFunc.PictureOpticflowDataResultArray[CurPictureIndex].OpticflowResultFOfPointsArray[j].Grad = Grad; } // 清除数组 Array.Resize(ref PictureDlateGreyArray, 0); CurrentPixtNeighbourArray.Clear(); } // 清除数组 Array.Resize(ref ReferencePictureGreyArray, 0); }