예제 #1
0
        bool PatternMatch(ref Sensor_data[,] s_data, int row, int col)
        {
            int[]     dirX = new int[] { -1, 0, 1, -1, 1, -1, 0, 1 };
            int[]     dirY = new int[] { -1, -1, -1, 0, 0, 1, 1, 1 };
            compare[] com  = new compare[] { compare.more_equal, compare.more_equal, compare.more_equal, compare.more, compare.more_equal, compare.more, compare.more, compare.more };

            short mid = get_date(ref s_data, row, col).value;

            if (mid < peak)
            {
                return(false);
            }

            for (int d = 0; d < dirX.Length; ++d)
            {
                int tr = row + dirY[d];
                int tc = col + dirX[d];
                if (!Sensor_data.BoundaryCheck(tr, tc))
                {
                    continue;
                }
                switch (com[d])
                {
                case compare.more:
                    if (get_date(ref s_data, tr, tc).value > mid || get_date(ref s_data, tr, tc).is_peak)
                    {
                        return(false);
                    }
                    break;

                case compare.more_equal:
                    if (get_date(ref s_data, tr, tc).value >= mid || get_date(ref s_data, tr, tc).is_peak)
                    {
                        return(false);
                    }
                    break;

                default:
                    break;
                }
            }
            get_date(ref s_data, row, col).is_peak = true;
            return(true);
        }
예제 #2
0
        List <short> get_arround7x7(ref Sensor_data[,] s_data, int row, int col)
        {
            List <short> ans = new List <short>();

            for (int y = -3; y <= +3; ++y)
            {
                for (int x = -3; x <= +3; ++x)
                {
                    int tr = row + y;
                    int tc = col + x;
                    if (!Sensor_data.BoundaryCheck(tr, tc))
                    {
                        ans.Add(0);
                    }
                    else
                    {
                        short sig = get_date(ref s_data, tr, tc).value;
                        ans.Add(sig);
                    }
                }
            }
            return(ans);
        }
예제 #3
0
        void callback_method(Socket sc)
        {
            int       frame_number  = 0;
            int       record_number = 0;
            Stopwatch sw            = new Stopwatch();

            while (true)
            {
                int    dataLength;
                byte[] myBufferBytes = new byte[100000];
                dataLength = sc.Receive(myBufferBytes);
                if (is_first)
                {
                    switch (dataLength)
                    {
                    case 3220:    //p3029
                        r    = 35;
                        c    = 46;
                        data = new Sensor_data[35, 46];
                        break;

                    case 6450:    //p3022
                        r    = 43;
                        c    = 75;
                        data = new Sensor_data[43, 75];
                        break;

                    case 3520:    //p3023
                        r    = 32;
                        c    = 55;
                        data = new Sensor_data[32, 55];
                        break;

                    case 1380:    //p3029
                        r    = 23;
                        c    = 30;
                        data = new Sensor_data[23, 30];
                        break;

                    default:
                        break;
                    }

                    is_first = false;
                }

                frame_number++;
                int now_r = 0, now_c = 0;

                for (int i = 0; i < dataLength; i = i + 2)
                {
                    Int16 ans = (Int16)((byte)myBufferBytes[i] << 8 | (byte)myBufferBytes[i + 1]);

                    data[now_r, now_c] = new Sensor_data(ans, false, now_r, now_c, (ans > Form1.peak - 1)?1:0, (ans > upper || ans < down) ? 1 : 0, (ans > upper + 10 || ans < down) ? 1 : 0, 0); //add label and area size initliaize
                    now_r = (now_c == c - 1) ? now_r + 1 : now_r;
                    now_c = (now_c == c - 1) ? 0 : now_c + 1;
                }

                if (Save_all)//跑C302收集資料用
                {
                    csv_class.write_all_csv(ref csv_all_swriter, ref data, r, c);
                    csv_class.write_bitmap_csv(ref csv_bitmap_swriter, ref data, r, c);
                }
                frame_id++;
                List <Save_data> sl  = new List <Save_data>();
                int          label   = 2;
                int          label_N = 2;
                int          label_C = 2;
                List <Point> peak    = new List <Point>();
                area_size_set.Clear();
                area_N_size_set.Clear();
                area_C_size_set.Clear();
                for (int i = 0; i < r; ++i)
                {
                    for (int j = 0; j < c; ++j)
                    {
                        if (PatternMatch(ref data, i, j)) //i 是 row j 是 col
                        {
                            List <short> ans    = get_arround(ref data, i, j);
                            area         area   = new area(0);
                            area         area_N = new area(0);
                            area         area_C = new area(0);
                            //  Console.WriteLine(data[i, j].value+" " +data[i,j].area_label);
                            if (data[i, j].area_label_N == 1) //caluate area if is label == 1
                            {
                                seed_filling_N(ref data, j, i, label_N, ref area_N);
                                area_N_size_set.Add(area_N);
                                label_N++;
                            }
                            else //already caluate area
                            {
                                area_N = area_N_size_set[data[i, j].area_label_N - 2];
                            }
                            //if (data[i, j].area_label_C == 1) //caluate area if is label == 1
                            //{

                            //    seed_filling_C(ref data, j, i, label_C, ref area_C);
                            //    area_C_size_set.Add(area_C);
                            //    label_C++;
                            //}
                            //else //already caluate area
                            //{
                            //    area_C = area_C_size_set[data[i, j].area_label_C - 2];
                            //}
                            if (data[i, j].area_label == 1) //caluate area if is label == 1
                            {
                                //   Console.WriteLine("xxx");
                                seed_filling(ref data, j, i, label, ref area);
                                area_size_set.Add(area);
                                label++;
                            }
                            else //already caluate area
                            {
                                area = area_size_set[data[i, j].area_label - 2];
                            }
                            double bevel_edge_lenght = Math.Sqrt(Math.Pow(area.min_x - area.max_x, 2) + Math.Pow(area.min_y - area.max_y, 2));
                            ans = get_arround7x7(ref data, i, j);
                            int second_area = 0;
                            int sum         = get_Negative_value(ref ans, ref second_area);
                            sl.Add(new Save_data(ans.ToArray(), frame_id, data_path + "Picture", area.size, bevel_edge_lenght, j, i, area_N.size));
                            have_peak = true;
                            peak.Add(new Point(j, i));
                            record_number++;
                        }
                    }
                }
                if (Save_all)
                {
                    using (StreamWriter swt = new StreamWriter(data_path + "pos.txt"))   //小寫TXT
                    {
                        for (int i = 0; i < peak.Count; i++)
                        {
                            swt.WriteLine(peak[i].X + " " + peak[i].Y);
                        }
                        swt.Flush();
                        swt.Close();
                    }
                    Save_all = false;
                }
                if (have_peak)
                {
                    save_frames.Add(new save_frame(sl.ToArray()));
                    have_peak = false;
                }
                double fps = sw.ElapsedMilliseconds;
                try
                {
                    BeginInvoke(new MethodInvoker(() =>
                    {
                        Fps_lb.Text = "Number number : " + record_number;
                    }));
                }
                catch (InvalidOperationException ex)
                {
                }
                pictureBox1.Invalidate();
            }
        }