/// <summary> /// Converts a 3 dimensional data set to a JSON Literal containing the Month, year and specificed key from the DataDictionary /// </summary> /// <param name="key">The key to use in the JSON Literal</param> /// <param name="data">The 3 dimensional data to serialize</param> /// <returns></returns> public string JsonEncode(string key, double[, ,] data) { StringBuilder output = new StringBuilder(); output.AppendLine("{"); output.AppendLine("'Year'" + ":" + yearInReview + ","); output.AppendLine("'Month'" + ":" + monthInReview + ","); output.AppendLine(" '" + key + "' " + ": "); int dayBound = data.GetUpperBound(0) + 1; int hourBound = data.GetUpperBound(1) + 1; int minBound = data.GetUpperBound(2) + 1; double[][][] dataz = new double[dayBound][][]; for (int d = 0; d < dayBound; d++) { dataz[d] = new double[hourBound][]; for (int h = 0; h < hourBound; h++) { dataz[d][h] = new double[minBound]; for (int m = 0; m < minBound; m++) { dataz[d][h][m] = data[d, h, m]; } } } output.Append(jsonSerializer.Serialize(dataz)); output.AppendLine("}"); return(output.ToString()); }
} // forward ///<summary> /// Performs the reverse transform from frequency or Hilbert domain to time /// domain for a given 3-D array depending on the used transform algorithm /// by by using the 1-D reverse transform multiple times. ///</summary> ///<remarks>Christian ([email protected]) 10.07.2010 18:09:54</remarks> ///<returns>Coefficients of 3-D time series of requested levels.</returns> public double[ ,, ] reverse(double[ ,, ] spcHilb) { int maxP = calcExponent(spcHilb.GetUpperBound(0) + 1); // no of rows int maxQ = calcExponent(spcHilb.GetUpperBound(1) + 1); // no of cols int maxR = calcExponent(spcHilb.GetUpperBound(2) + 1); // no of high return(reverse(spcHilb, maxP, maxQ, maxR)); } // reverse
} // reverse ///<summary> /// Performs the forward transform from time domain to frequency or Hilbert /// domain for a given 3-D array depending on the used transform algorithm /// by using the 1-D forward transform multiple times. ///</summary> ///<remarks>Christian ([email protected]) 10.07.2010 18:08:17</remarks> ///<returns>Coefficients of 3-D frequency or Hilbert space.</returns> public double[ ,, ] forward(double[ ,, ] spcTime) { int maxP = calcExponent(spcTime.GetUpperBound(0) + 1); // no of rows int maxQ = calcExponent(spcTime.GetUpperBound(1) + 1); // no of cols int maxR = calcExponent(spcTime.GetUpperBound(2) + 1); // no of high return(forward(spcTime, maxP, maxQ, maxR)); } // forward
public static void COPY(double[,,] source, double[,,] destination) { for (int i = 0; i < source.GetUpperBound(0) + 1; i++) { for (int j = 0; j < source.GetUpperBound(1) + 1; j++) { for (int n = 0; n < source.GetUpperBound(2) + 1; n++) { destination[i, j, n] = source[i, j, n]; } } } }
public static void ERROR(double[,,] y, Tuple <double, double, double> steps, double[,,] z) { for (int i = 0; i < y.GetUpperBound(0) + 1; i++) { for (int j = 0; j < y.GetUpperBound(1) + 1; j++) { for (int n = 0; n < y.GetUpperBound(2) + 1; n++) { z[i, j, n] = Math.Abs(y[i, j, n] - U(steps.Item1 * i, steps.Item2 * j, steps.Item3 * n)); } } } }
} // reverse ///<summary> /// Performs the reverse transform from frequency or Hilbert domain to time /// domain of certain levels for a given 3-D array depending on the used /// transform algorithm by by using the 1-D reverse transform multiple /// times. /// lvlP - level to start reconstruction for dimension columns of the cube /// lvlQ - level to start reconstruction for dimension height of the cube /// lvlR - level to start reconstruction for dimension rows of the cube ///</summary> ///<remarks>Christian ([email protected]) 22.03.2015 13:01:47</remarks> ///<returns>Coefficients of 3-D time series of requested levels.</returns> public double[ ,, ] reverse(double[ ,, ] spcHilb, int lvlP, int lvlQ, int lvlR) { int noOfRows = spcHilb.GetUpperBound(0) + 1; // no of rows int noOfCols = spcHilb.GetUpperBound(1) + 1; // no of cols int noOfHigh = spcHilb.GetUpperBound(2) + 1; // no of high double[ ,, ] spcTime = new double[noOfRows, noOfCols, noOfHigh]; for (int i = 0; i < noOfRows; i++) { double[ , ] matHilb = new double[noOfCols, noOfHigh]; for (int j = 0; j < noOfCols; j++) { for (int k = 0; k < noOfHigh; k++) { double val = spcHilb[i, j, k]; matHilb[j, k] = val; } // high } // cols double[ , ] matTime = reverse(matHilb, lvlP, lvlQ); // 2-D cols & high for (int j = 0; j < noOfCols; j++) { for (int k = 0; k < noOfHigh; k++) { double val = matTime[j, k]; spcTime[i, j, k] = val; } // high } // cols } // rows for (int j = 0; j < noOfCols; j++) { for (int k = 0; k < noOfHigh; k++) { double[] arrHilb = new double[noOfRows]; for (int i = 0; i < noOfRows; i++) { double val = spcTime[i, j, k]; arrHilb[i] = val; } // rows double[] arrTime = reverse(arrHilb, lvlR); // 1-D reverse rows for (int i = 0; i < noOfRows; i++) { double val = arrTime[i]; spcTime[i, j, k] = val; } // rows } // high } // cols return(spcTime); } // reverse
private void Mittelwert(double[,,] z) { double summe = 0; for (int i = 0; i <= z.GetUpperBound(0); i++) { for (int j = 0; j <= z.GetUpperBound(1); j++) { for (int k = 0; k <= z.GetUpperBound(2); k++) { summe += z[i, j, k]; } } } LblAnzeige.Text = "Mittelwert: " + summe / z.Length; }
public static double MAX(double[,,] y) { double result = 0.0; for (int i = 0; i < y.GetUpperBound(0) + 1; i++) { for (int j = 0; j < y.GetUpperBound(1) + 1; j++) { for (int n = 0; n < y.GetUpperBound(2) + 1; n++) { result = y[i, j, n] > result ? y[i, j, n] : result; } } } return(result); }
public static void PRINT(double[,,] array) { for (int n = 0; n < array.GetUpperBound(2) + 1; n++) { // double tau = (double)n / (double)array.GetUpperBound(2); double[,] output = ARR3DTO2D(array, 2, n); // Console.WriteLine($"tau={tau:0.000}"); PRINT(output); } }
/// <summary> /// Converts a 3 dimensional dataSet to a 2 dimensional dataSet /// </summary> /// <param name="dataSet">The dataSet to fold</param> /// <returns></returns> public double[,] ConvertTo2D(double[, ,] dataSet) { //A 2d matrix of only days and hours int dayEnd = dataSet.GetUpperBound(0) + 1; int hourEnd = dataSet.GetUpperBound(1) + 1; double[,] dMatrix = new double[dayEnd, hourEnd]; double HoursTotal = 0; for (int Day = 0; Day < dayEnd; Day++) { for (int Hour = 0; Hour < hourEnd; Hour++) { HoursTotal = 0; for (int Minute = 0, minuteEnd = dataSet.GetUpperBound(2) + 1; Minute < minuteEnd; Minute++) { HoursTotal += dataSet[Day, Hour, Minute]; /// DateUtility.OccurancesOfDayInMonth((DayOfWeek)Day, monthInReview, yearInReview); }//Minutes HoursTotal /= 60; //minutes in a hour dMatrix[Day, Hour] = HoursTotal; }//Hours }//Days return(dMatrix); }
/// <summary> /// Converts a 3 dimensional dataSet to a 2 dimensional dataSet /// </summary> /// <param name="dataSet">The dataSet to fold</param> /// <param name="day">The day to focus</param> /// <returns></returns> public double[,] ConvertTo2D(double[, ,] dataSet, DayOfWeek day) { //A 2d matrix of only days and hours int hourEnd = dataSet.GetUpperBound(1) + 1; double[,] dMatrix = new double[1, hourEnd]; double HoursTotal = 0; for (int Hour = 0; Hour < hourEnd; Hour++) { HoursTotal = 0; for (int Minute = 0; Minute < 60; Minute++) { HoursTotal += dataSet[(int)day, Hour, Minute]; // / DateUtility.OccurancesOfDayInMonth(day, monthInReview, yearInReview); }//Minutes HoursTotal /= 60; //minutes in a hour dMatrix[0, Hour] = HoursTotal; }//Hours return(dMatrix); }
//////////////////////////////////////////////////////////////////////////////// #region Public Methods /// <summary> /// Computes one frame of the reaction. /// </summary> /// <returns>An array containing the reaction products for the next frame. </returns> public unsafe double[, ,] ComputeReaction() { Debug.Assert(CheckInvariant(), "ComputeReaction: CheckInvariant failed"); double Xa; double Xb; double Xc; double c; double d; double f; double g0; double feedbackFromC; double feedbackFromB; iteration++; // If boundary conditions have changed since the previous frame, update them. if (this._boundaryConditionsPrev != this._boundaryConditions) { this.SetBoundaryConditions(this._boundaryConditions); this._boundaryConditionsPrev = this._boundaryConditions; } // Copy boundary values to the out buffer. for (int i = 0; i < vesselWidth; i++) { reactionOut[indexA, i, 0] = reaction[indexA, i, 0]; reactionOut[indexB, i, 0] = reaction[indexB, i, 0]; reactionOut[indexC, i, 0] = reaction[indexC, i, 0]; reactionOut[indexA, i, vesselHeight - 1] = reaction[indexA, i, vesselHeight - 1]; reactionOut[indexB, i, vesselHeight - 1] = reaction[indexB, i, vesselHeight - 1]; reactionOut[indexC, i, vesselHeight - 1] = reaction[indexC, i, vesselHeight - 1]; } for (int j = 0; j < vesselHeight; j++) { reactionOut[indexA, 0, j] = reaction[indexA, 0, j]; reactionOut[indexB, 0, j] = reaction[indexB, 0, j]; reactionOut[indexC, 0, j] = reaction[indexC, 0, j]; reactionOut[indexA, vesselWidth - 1, j] = reaction[indexA, vesselWidth - 1, j]; reactionOut[indexB, vesselWidth - 1, j] = reaction[indexB, vesselWidth - 1, j]; reactionOut[indexC, vesselWidth - 1, j] = reaction[indexC, vesselWidth - 1, j]; } // Traverse the grid and compute concentrations for // all three reactants. This implements the Gontar model. for (int i = 1; i < vesselWidth - 1; i++) { for (int j = 1; j < vesselHeight - 1; j++) { try { // Compute concentrations at cell (i,j). feedbackFromC = Math.Exp(-W1 / weight(indexC, i, j)); feedbackFromB = Math.Exp(-W2 * weight(indexB, i, j)); g0 = (K1 * K2 * feedbackFromC * feedbackFromB) / (1.0 + K1 * feedbackFromC); // Compute concentrations at cell (i,j). //c = -W1 / weight(2, i, j); //f = -W2 * weight(1, i, j); //e_to_c = Math.Exp(c); //e_to_f = Math.Exp(f); //d = 1.0 + K1 * e_to_c; //g0 = (K1 * K2 * e_to_c * e_to_f) / d; Xc = b * (g0 / (g0 + 1)); if (Xc <= minConcentration) { Xc = minConcentration; } Xb = (K1 * feedbackFromC / (1 + K1 * feedbackFromC)) * (b - Xc); if (Xb <= minConcentration) { Xb = minConcentration; } Xa = b - Xb - Xc; if (Xa <= minConcentration) { Xa = minConcentration; } if (Xa > b) { Xa = b; } if (Xb > b) { Xb = b; } if (Xc > b) { Xc = b; } reactionOut[indexA, i, j] = Xa; reactionOut[indexB, i, j] = Xb; reactionOut[indexC, i, j] = Xc; } catch (Exception ex) { Console.WriteLine("caught exception: ", ex.ToString()); } } } int ubi = reaction.GetUpperBound(1) + 1; int ubj = reaction.GetUpperBound(2) + 1; // Copy the out buffer to the in buffer. fixed(double *pOutBuff = reactionOut, pInBuff = reaction) { uint buffSize = (uint)(3 * ubi * ubj * sizeof(double)); uint count = buffSize; double *ps = pOutBuff; double *pd = pInBuff; lock (reactionOut.SyncRoot) { try { CopyMemory((void *)pd, (void *)ps, count); } catch (Exception ex) { Trace.WriteLine(ex.Message); } } } // Raise the IterationCompleted event. IterationCompletedEventArgs e = new IterationCompletedEventArgs(this.iteration); OnInterationCompleted(e); return(reactionOut); }
private void button6_Click(object sender, EventArgs e) { int Num1, Num2; try { Num1 = Convert.ToInt32(textBox5.Text); Num2 = Convert.ToInt32(textBox6.Text); if (Num1 < 1 || Num2 < 1 || Num1 > WorkingImage.Count | Num2 > WorkingImage.Count) { throw new Exception(); } } catch { LogOutputTextBox.Text += "Номера версій введено невірно" + Environment.NewLine; return; } double[,,] Mat1 = WorkingImage[Num1 - 1]; double[,,] Mat2 = WorkingImage[Num2 - 1]; int height = Mat1.GetUpperBound(1) + 1; int width = Mat1.GetUpperBound(2) + 1; if (height != Mat2.GetUpperBound(1) + 1 || width != Mat2.GetUpperBound(2) + 1) { LogOutputTextBox.Text += "Розміри версій не співпадають" + Environment.NewLine; return; } double[,,] Eps = new double[3, height, width]; double[] Mean = new double[3]; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { Mean[0] += (Eps[0, i, j] = Mat1[0, i, j] - Mat2[0, i, j]); Mean[1] += (Eps[1, i, j] = Mat1[1, i, j] - Mat2[1, i, j]); Mean[2] += (Eps[2, i, j] = Mat1[2, i, j] - Mat2[2, i, j]); } } Mean[0] /= height * width - 1; Mean[1] /= height * width - 1; Mean[2] /= height * width; double[] Sigma = new double[3]; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { Sigma[0] += (Eps[0, i, j] - Mean[0]) * (Eps[0, i, j] - Mean[0]); Sigma[1] += (Eps[1, i, j] - Mean[1]) * (Eps[1, i, j] - Mean[1]); Sigma[2] += (Eps[2, i, j] - Mean[2]) * (Eps[2, i, j] - Mean[2]); } } Sigma[0] /= height * width - 1; Sigma[1] /= height * width - 1; Sigma[2] /= height * width - 1; Sigma[0] = Math.Sqrt(Sigma[0]); Sigma[1] = Math.Sqrt(Sigma[1]); Sigma[2] = Math.Sqrt(Sigma[2]); LogOutputTextBox.Text += "Середньоквадратичне відхилення похибки:" + Environment.NewLine; LogOutputTextBox.Text += "R: " + Math.Round(Sigma[0], 6) + Environment.NewLine; LogOutputTextBox.Text += "G: " + Math.Round(Sigma[1], 6) + Environment.NewLine; LogOutputTextBox.Text += "B: " + Math.Round(Sigma[2], 6) + Environment.NewLine + Environment.NewLine; double[] PSNR = new double[3]; PSNR[0] = 10 * Math.Log10((255 * 255) / (Sigma[0] * Sigma[0])); PSNR[1] = 10 * Math.Log10((255 * 255) / (Sigma[1] * Sigma[1])); PSNR[2] = 10 * Math.Log10((255 * 255) / (Sigma[2] * Sigma[2])); LogOutputTextBox.Text += "ПСНР:" + Environment.NewLine; LogOutputTextBox.Text += "R: " + Math.Round(PSNR[0], 6) + Environment.NewLine; LogOutputTextBox.Text += "G: " + Math.Round(PSNR[1], 6) + Environment.NewLine; LogOutputTextBox.Text += "B: " + Math.Round(PSNR[2], 6) + Environment.NewLine + Environment.NewLine; double[] RelErr = new double[3]; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { RelErr[0] += (Math.Abs(Eps[0, i, j]) / Mat1[0, i, j]); RelErr[1] += (Math.Abs(Eps[1, i, j]) / Mat1[1, i, j]); RelErr[2] += (Math.Abs(Eps[2, i, j]) / Mat1[2, i, j]); } } RelErr[0] /= height * width; RelErr[1] /= height * width; RelErr[2] /= height * width; LogOutputTextBox.Text += "Відносна похибка від першої версії:" + Environment.NewLine; LogOutputTextBox.Text += "R: " + Math.Round(RelErr[0] / 100, 6) + "%" + Environment.NewLine; LogOutputTextBox.Text += "G: " + Math.Round(RelErr[1] / 100, 6) + "%" + Environment.NewLine; LogOutputTextBox.Text += "B: " + Math.Round(RelErr[2] / 100, 6) + "%" + Environment.NewLine + Environment.NewLine; RelErr = new double[3]; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { RelErr[0] += (Math.Abs(Eps[0, i, j]) / Mat2[0, i, j]); RelErr[1] += (Math.Abs(Eps[1, i, j]) / Mat2[1, i, j]); RelErr[2] += (Math.Abs(Eps[2, i, j]) / Mat2[2, i, j]); } } RelErr[0] /= height * width; RelErr[1] /= height * width; RelErr[2] /= height * width; LogOutputTextBox.Text += "Відносна похибка від другої версії:" + Environment.NewLine; LogOutputTextBox.Text += "R: " + Math.Round(RelErr[0] / 100, 6) + "%" + Environment.NewLine; LogOutputTextBox.Text += "G: " + Math.Round(RelErr[1] / 100, 6) + "%" + Environment.NewLine; LogOutputTextBox.Text += "B: " + Math.Round(RelErr[2] / 100, 6) + "%" + Environment.NewLine + Environment.NewLine; }
public static double[,] ARR3DTO2D(double[,,] array, int axis, int index) { double[,] result = new double[0, 0]; switch (axis) { case 0: result = new double[array.GetUpperBound(1) + 1, array.GetUpperBound(2) + 1]; for (int j = 0; j < array.GetUpperBound(1) + 1; j++) { for (int n = 0; n < array.GetUpperBound(2) + 1; n++) { result[j, n] = array[index, j, n]; } } break; case 1: result = new double[array.GetUpperBound(0) + 1, array.GetUpperBound(2) + 1]; for (int i = 0; i < array.GetUpperBound(0) + 1; i++) { for (int n = 0; n < array.GetUpperBound(2) + 1; n++) { result[i, n] = array[i, index, n]; } } break; case 2: result = new double[array.GetUpperBound(0) + 1, array.GetUpperBound(1) + 1]; for (int i = 0; i < array.GetUpperBound(0) + 1; i++) { for (int j = 0; j < array.GetUpperBound(1) + 1; j++) { result[i, j] = array[i, j, index]; } } break; } return(result); }
public void Flash_detector(object sender, EventArgs e) { if (total_frame_count == F_count) { Application.Idle -= Flash_detector; Application.Idle -= start_video_Click; Application.Idle -= chart_showing; SystemSounds.Beep.Play(); status.Text = "Finish"; if (stock_file_run.Checked == true) { Application.Idle += save_data; } } else { ImageFram = CamCapture.QueryFrame(); time_index = CamCapture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_POS_MSEC); flash = 0; ImageFram1 = ImageFram; Image <Hsv, Byte> hsvImage = ImageFram.Convert <Hsv, Byte>(); Image <Gray, Byte> ResultImage = new Image <Gray, Byte>(hsvImage.Width, hsvImage.Height); Image <Gray, Byte> IlowCh0 = new Image <Gray, Byte>(hsvImage.Width, hsvImage.Height, new Gray(ll)); Image <Gray, Byte> IHiCh0 = new Image <Gray, Byte>(hsvImage.Width, hsvImage.Height, new Gray(hl)); pictureBox1.Image = ImageFram1.ToBitmap(pictureBox1.Width, pictureBox1.Height); /* * Image<Hsv, Byte> hsvImage2 = ImageFram.Convert<Hsv, Byte>(); //Convert RGB > HSV. * Image<Gray, Byte> ResultImage2 = new Image<Gray, Byte>(hsvImage2.Width, hsvImage2.Height); * * * Image<Gray, Byte> IlowCh2 = new Image<Gray, Byte>(hsvImage2.Width, hsvImage2.Height, new Gray(15)); * Image<Gray, Byte> IHiCh2 = new Image<Gray, Byte>(hsvImage2.Width, hsvImage2.Height, new Gray(255)); * * CvInvoke.cvInRange(hsvImage[0], IlowCh0, IHiCh0, ResultImage); * CvInvoke.cvInRange(hsvImage2[2], IlowCh2, IHiCh2, ResultImage2); * * * CvInvoke.cvAnd(ResultImage, ResultImage2, ResultImage, (IntPtr)null); */ //Use cvinrange() method and hsvImage[0] = hsvimage channel 0 if (radioButton1.Checked == true) { CvInvoke.cvInRange(hsvImage[0], IlowCh0, IHiCh0, ResultImage); } if (radioButton2.Checked == true) { CvInvoke.cvInRange(hsvImage[1], IlowCh0, IHiCh0, ResultImage); } if (radioButton3.Checked == true) { CvInvoke.cvInRange(hsvImage[2], IlowCh0, IHiCh0, ResultImage); } re_noise = int.Parse(comboBox2.Text); CvInvoke.cvErode(ResultImage, ResultImage, (IntPtr)null, re_noise); CvInvoke.cvDilate(ResultImage, ResultImage, (IntPtr)null, re_noise); Image <Gray, Byte> imgForContour = new Image <Gray, byte>(ResultImage.Width, ResultImage.Height); CvInvoke.cvCopy(ResultImage, imgForContour, System.IntPtr.Zero); IntPtr storage = CvInvoke.cvCreateMemStorage(0); IntPtr contour = new IntPtr(); CvInvoke.cvFindContours(imgForContour, storage, ref contour, System.Runtime.InteropServices.Marshal.SizeOf(typeof(MCvContour)), Emgu.CV.CvEnum.RETR_TYPE.CV_RETR_EXTERNAL, Emgu.CV.CvEnum.CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_NONE, new Point(0, 0)); Seq <Point> seq = new Seq <Point>(contour, null); for (; seq != null && seq.Ptr.ToInt32() != 0; seq = seq.HNext) { Rectangle bndRec = CvInvoke.cvBoundingRect(seq, 1); double areaC = CvInvoke.cvContourArea(seq, MCvSlice.WholeSeq, 1) * -1; if (areaC >= pixcut_low && areaC <= pixcut_high) { CvInvoke.cvRectangle(ImageFram, new Point(bndRec.X, bndRec.Y), new Point(bndRec.X + bndRec.Width, bndRec.Y + bndRec.Height), new MCvScalar(0, 0, 255), 2, LINE_TYPE.CV_AA, 0); flash = Convert.ToInt32(areaC); ////// x_position = bndRec.X + bndRec.Width / 2; ////// y_position = bndRec.Y + bndRec.Height / 2; ////// // XPos.Text = xFace.ToString(); // YPos.Text = yFace.ToString(); /*/ * time_collect[i] = time_index; // เก็บค่าเวลาที่เกิดการกระพริบ * x_pos[i] = x_position; // เก็บพิกัด x ของการกระพริบ * y_pos[i] = y_position; // เก็บพิกัด y ของการกระพริบ * * /*/ error_position = int.Parse(error_area_comboBox.Text); if (areaC > 0) { if (y_position >= 0) { y_chart = 1080 - y_position; ////////// fix convert position 26/8/2018 from 720-->1080 this.chart2.Series["position"].Points.AddXY(x_position, y_chart); //////////////////////////////// chart plot } for (count_no_fire = 1; count_no_fire <= data_collection.GetUpperBound(0); count_no_fire++) { if (data_collection[count_no_fire, 2, 2] == 1 | data_collection[count_no_fire, 2, 2] == 2) //// sss { x_compare = Convert.ToInt32(data_collection[count_no_fire, 1, 1]); y_compare = Convert.ToInt32(data_collection[count_no_fire, 2, 1]); x_result = Math.Abs(x_compare - x_position); y_result = Math.Abs(y_compare - y_position); if (x_result <= error_position & y_result <= error_position) { last_list = Convert.ToInt32(data_collection[count_no_fire, 1, 2]); if (time_index == data_collection[count_no_fire, last_list - 1, 1]) { data_collection[count_no_fire, 1, 1] = x_position; data_collection[count_no_fire, 2, 1] = y_position; data_collection[count_no_fire, last_list - 1, 2] = areaC + data_collection[count_no_fire, last_list - 1, 2]; /// **new edit data_collection[count_no_fire, 2, 2] = 2; break; } else { last_list = Convert.ToInt32(data_collection[count_no_fire, 1, 2]); data_collection[count_no_fire, 1, 1] = x_position; data_collection[count_no_fire, 2, 1] = y_position; data_collection[count_no_fire, last_list, 1] = time_index; data_collection[count_no_fire, last_list, 2] = areaC; last_list++; data_collection[count_no_fire, 1, 2] = last_list; data_collection[count_no_fire, 2, 2] = 2; break; } } } else { position_count = 3; last_list = 3; data_collection[count_no_fire, 1, 1] = x_position; data_collection[count_no_fire, 2, 1] = y_position; data_collection[count_no_fire, last_list, 1] = time_index; data_collection[count_no_fire, last_list, 2] = areaC; last_list++; data_collection[count_no_fire, 1, 2] = last_list; data_collection[count_no_fire, 2, 2] = 2; /////////// status ***new edit position_collection[count_no_fire, position_count, 0] = Convert.ToInt32(data_collection[count_no_fire, 1, 1]); position_collection[count_no_fire, position_count, 1] = Convert.ToInt32(data_collection[count_no_fire, 2, 1]); //position_count++; // fixing 27/8/2018 position_collection[count_no_fire, 1, 2] = position_count; break; } } } } } for (count_no_fire = 1; count_no_fire <= data_collection.GetUpperBound(0); count_no_fire++) { last_list = Convert.ToInt32(data_collection[count_no_fire, 1, 2]); if (data_collection[count_no_fire, 2, 2] == 1) //// sss { data_collection[count_no_fire, last_list, 1] = time_index; data_collection[count_no_fire, last_list, 2] = 0; last_list++; data_collection[count_no_fire, 1, 2] = last_list; } if (data_collection[count_no_fire, 2, 2] == 2) //// sss { position_count = position_collection[count_no_fire, 1, 2]; position_collection[count_no_fire, position_count, 0] = Convert.ToInt32(data_collection[count_no_fire, 1, 1]); position_collection[count_no_fire, position_count, 1] = Convert.ToInt32(data_collection[count_no_fire, 2, 1]); position_count++; position_collection[count_no_fire, 1, 2] = position_count; data_collection[count_no_fire, 2, 2] = 1; } } pictureBox1.Image = ImageFram.ToBitmap(pictureBox1.Width, pictureBox1.Height); //นำผลการคิ่วรี่เฟรมมาแสดงยัง ImageBox pictureBox2.Image = ResultImage.ToBitmap(pictureBox2.Width, pictureBox2.Height); CvInvoke.cvReleaseMemStorage(ref storage); // คืนหน่วยความจำ total_frame_count++; present_frame.Text = total_frame_count.ToString(); } }