//Covert from x,y to s,a  return: true->success  false->fail
 public static bool ConvertRes(CSVHandler.ResPackage inputxy, ref CSVHandler.CalResPackage outputsa)
 {
     try
     {
         int CameraNum = ConfigHandler.GetCameraNum(inputxy.SerialNum);
         if (CameraNum == 999 || CameraNum == 0)
         {
             Console.WriteLine("That is a wrong camera Serialnum for result conversion!\n");
             return(false);
         }
         //Copy the SerialNum and Timestamp
         outputsa.SerialNum = CameraNum;
         outputsa.Timestamp = inputxy.Timestamp;
         for (int i = 0; i < CSVHandler.DataRows; i++)
         {
             //Calculate the s a from x y
             if (inputxy.x[i] == 0 || inputxy.y[i] == 0)
             {
                 outputsa.s[i] = 0;
                 outputsa.a[i] = 0;
             }
             else
             {
                 try
                 {
                     float cd = Convert.ToSingle(Math.Atan((ConfigHandler.CameraVo[CameraNum] - inputxy.y[i]) / ConfigHandler.CameraFy[CameraNum]));
                     float x  = inputxy.x[i];
                     //ay load the device degree
                     outputsa.a[i] = System.Convert.ToSingle(ConfigHandler.CameraK00[CameraNum] + ConfigHandler.CameraK10[CameraNum] * cd + ConfigHandler.CameraK01[CameraNum] * x + ConfigHandler.CameraK11[CameraNum] * cd * x + ConfigHandler.CameraK02[CameraNum] * x * x);
                     float Yy    = cd;
                     float alpha = System.Convert.ToSingle(ConfigHandler.CameraDegree[CameraNum] * 3.14159265358 / 180 + outputsa.a[i]);
                     float Fx    = Convert.ToSingle(ConfigHandler.CameraP00[CameraNum] + ConfigHandler.CameraP10[CameraNum] * x + ConfigHandler.CameraP01[CameraNum] * Yy + ConfigHandler.CameraP20[CameraNum] * x * x + ConfigHandler.CameraP11[CameraNum] * x * Yy + ConfigHandler.CameraP02[CameraNum] * Yy * Yy);
                     //float Fx = (_Default.CameraP1[CameraNum] * SockPackc.s[i] * SockPackc.s[i] * SockPackc.s[i] + _Default.CameraP2[CameraNum] * SockPackc.s[i] * SockPackc.s[i] + _Default.CameraP3[CameraNum] * SockPackc.s[i] + _Default.CameraP4[CameraNum]);
                     float scor = System.Convert.ToSingle((ConfigHandler.CameraBmm[CameraNum] * Math.Tan(ConfigHandler.CameraPhi[CameraNum] + Math.Atan((ConfigHandler.CameraUo[CameraNum] - inputxy.x[i]) / ConfigHandler.CameraFx[CameraNum])) + ConfigHandler.CameraM[CameraNum]) / Fx);
                     float num  = (scor * ConfigHandler.CameraBmm[CameraNum] + (scor - ConfigHandler.CameraM[CameraNum]) * ConfigHandler.BP1);
                     float den  = Convert.ToSingle(ConfigHandler.CameraBmm[CameraNum] + (ConfigHandler.CameraM[CameraNum] - scor) * (ConfigHandler.BP2 * Math.Cos(alpha) + ConfigHandler.BP3 * Math.Sin(alpha)));
                     outputsa.s[i] = num / den;
                 }
                 catch (System.NullReferenceException)
                 {
                 }
             }
         }
         return(true);
     }
     catch (System.NullReferenceException)
     {
         return(false);
     }
 }
Exemple #2
0
        // Read and Handle the csv-Result File (Multi-Line)
        public static void HandleCSV_multiLine(object param)
        {
            HandleCSVParam hcsv_param = (HandleCSVParam)param;
            MetroTunnelDB  database   = new MetroTunnelDB();
            int            record_id  = hcsv_param.record_id;
            string         filepath   = hcsv_param.filepath;
            MainWindow     mw         = hcsv_param.mw;
            FileStream     fs         = new FileStream(filepath, FileMode.Open, System.IO.FileAccess.Read);
            StreamReader   sr         = new StreamReader(fs);

            // Record the Line once
            string strline;

            string[] arrline     = null;
            string[] tablehead   = null;
            int      columncount = 0;
            bool     isfirst     = true;
            int      linecount   = 0;

            // Multi-Line Param
            const int         line_query_once = 50;
            List <ResPackage> LinePackList    = new List <ResPackage>();


            while ((strline = sr.ReadLine()) != null)
            {
                //Handle one line each time
                ResPackage LinePack = new ResPackage();
                LinePack.x = new float[DataRows];
                LinePack.y = new float[DataRows];
                //CalResPackage LineCalPack = new CalResPackage();
                //LineCalPack.s = new float[DataRows];
                //LineCalPack.a = new float[DataRows];
                arrline = strline.Split(',');
                if (isfirst)
                {
                    columncount = arrline.Length;
                    isfirst     = false;
                }
                for (int i = 0; i < columncount; i++)
                {
                    try
                    {
                        //SerialNum
                        if (i == 0)
                        {
                            LinePack.SerialNum = arrline[0].ToCharArray();
                        }
                        //Timestamp
                        else if (i == 1)
                        {
                            LinePack.Timestamp = Convert.ToInt32(arrline[1]);
                        }
                        else
                        {
                            int count = i / 2 - 1;
                            //x
                            if (i % 2 == 0)
                            {
                                LinePack.x[count] = Convert.ToSingle(arrline[i]);
                            }
                            //y
                            else
                            {
                                // LinePack.y[count] = Convert.ToSingle(arrline[i]);
                                LinePack.y[count] = Convert.ToSingle(count);
                            }
                        }
                    }
                    catch (System.NullReferenceException)
                    {
                        //SerialNum
                        if (i == 0)
                        {
                            continue;
                        }
                        //Timestamp
                        else if (i == 1)
                        {
                            continue;
                        }
                        else
                        {
                            int count = i / 2 - 1;
                            //x
                            if (i % 2 == 0)
                            {
                                LinePack.x[count] = 0;
                            }
                            //y
                            else
                            {
                                LinePack.y[count] = 0;
                            }
                        }
                    }
                    catch (System.IndexOutOfRangeException)
                    {
                        //SerialNum
                        if (i == 0)
                        {
                            continue;
                        }
                        //Timestamp
                        else if (i == 1)
                        {
                            continue;
                        }
                        else
                        {
                            int count = i / 2 - 1;
                            //x
                            if (i % 2 == 0)
                            {
                                LinePack.x[count] = 0;
                            }
                            //y
                            else
                            {
                                LinePack.y[count] = 0;
                            }
                        }
                    }
                }

                LinePackList.Add(LinePack);
                //Convert to s-a
                //bool ret = false;
                //ret = ModelHandler.ConvertRes(LinePack, ref LineCalPack);
                //if (!ret)
                //{
                //    Console.WriteLine("Covertion Failed ! ! !\n");
                //}

                if (LinePackList.Count % line_query_once == 0)
                {
                    DataRaw[] dataRaws = new DataRaw[LinePackList.Count];
                    for (int l = 0; l < LinePackList.Count; l++)
                    {
                        //Get DataRaw
                        dataRaws[l] = new DataRaw(record_id, LinePackList[l].Timestamp, ConfigHandler.GetCameraNum(LinePackList[l].SerialNum), LinePackList[l].x, LinePackList[l].y);
                        mw.line_counter++;
                    }
                    //Send to MySQL
                    int retm = 0;
                    try
                    {
                        retm = database.InsertIntoDataRaw(dataRaws);
                    }
                    catch (System.Exception)
                    {
                        mw.DebugWriteLine("截面数据库插入异常");
                    }
                    if (!Convert.ToBoolean(retm))
                    {
                        mw.DebugWriteLine("截面数据库插入异常");
                    }
                    linecount = 0;
                    LinePackList.Clear();
                }
                // mw.SubProcessReport(mw.line_counter++);
            }
            if (LinePackList.Count > 0)
            {
                DataRaw[] dataRaws = new DataRaw[LinePackList.Count];
                for (int l = 0; l < LinePackList.Count; l++)
                {
                    //Get DataRaw
                    dataRaws[l] = new DataRaw(record_id, LinePackList[l].Timestamp, ConfigHandler.GetCameraNum(LinePackList[l].SerialNum), LinePackList[l].x, LinePackList[l].y);
                    mw.line_counter++;
                }
                //Send to MySQL
                int retm = 0;
                try
                {
                    retm = database.InsertIntoDataRaw(dataRaws);
                }
                catch (System.Exception)
                {
                    mw.DebugWriteLine("截面数据库插入异常");
                }
                if (!Convert.ToBoolean(retm))
                {
                    mw.DebugWriteLine("截面数据库插入异常");
                }
            }

            DataAnalyze.threadControlCounter += 1;
        }
        //Deal with EncodeResult
        public static void ScanEncodeResult(object o_filepath, int record_id)
        {
            string           filepath     = (string)o_filepath;
            string           EncodeResult = filepath + "\\EncodeResult";
            List <FileNames> Filelist     = new List <FileNames>();

            GetSystemAllPath.GetallDirectory(Filelist, EncodeResult);
            //Console.WriteLine("---Decoding " + EncodeResult + ".....\n");
            if (Filelist.Count() < 1)
            {
                mw.DebugWriteLine("未发现视频文件");
                return;
            }
            mw.DebugWriteLine("解析视频目录" + EncodeResult + "...");
            for (int i = 0; i < Filelist.Count(); i++)
            {
                string mjpegpath  = EncodeResult + "\\" + Filelist[i].text + "\\" + Filelist[i].children[0].text;
                string outputpath = filepath + "\\DecodeResult\\" + Filelist[i].text;
                //Console.WriteLine("------Decoding " + Filelist[i].text + ".....\n");
                mw.DebugWriteLine("解析视频文件" + Filelist[i].text + "...");
                //Decode the mjpeg
                MjpegHandler.DecodeParam param;
                param.inputvideo = mjpegpath;
                param.outputpath = outputpath;
                Thread DecodeThread = new Thread(MjpegHandler.CallPythonToDecode);
                DecodeThread.Start(param);
                //MjpegHandler.CallPythonToDecode(param);
            }
            mw.DebugWriteLine("导入视频序列" + EncodeResult + "...");
            for (int i = 0; i < Filelist.Count(); i++)
            {
                mw.DebugWriteLine("导入视频序列" + Filelist[i].text + "...");
                string image_root_url = filepath + "\\DecodeResult\\" + Filelist[i].text;
                string mjpeg_csv_path = EncodeResult + "\\" + Filelist[i].text + "\\" + Filelist[i].children[1].text;
                // Get CameraNum from filename
                int cam_num = ConfigHandler.GetCameraNum(Filelist[i].children[1].text.Split("_")[1].Split(".")[0].ToCharArray());
                if (cam_num < 1 || cam_num == 999)
                {
                    continue;
                }
                CSVHandler.HandleTimestampParam htime_param;
                htime_param.record_id       = record_id;
                htime_param.cam_num         = cam_num;
                htime_param.csv_file_path   = mjpeg_csv_path;
                htime_param.mjpeg_root_path = image_root_url;
                htime_param.mw = mw;
                // Handle Timestamp csv
                //CSVHandler.HandleTimestamp(htime_param);
                // Handle Timestamp csv mtd
                Thread htime_thread = new Thread(CSVHandler.HandleTimestamp);
                htime_thread.Start(htime_param);

                // mw.DebugWriteLine("导入视频序列" + Filelist[i].text + "完成");
            }
            mw.DebugWriteLine("导入视频序列" + EncodeResult + "完成");

            while (threadControlCounter < (Filelist.Count() * 2))
            {
                int task_now = (int)(GetSystemAllPath.GetDirectorySize(filepath + "\\DecodeResult") / 1000000);
                mw.SubProcessReport(task_now + mw.line_counter);
                Thread.Sleep(100);
            }
            threadControlCounter = 0;
            //Console.WriteLine("---Decoding Finished " + EncodeResult + ".....\n");
            mw.DebugWriteLine("解析视频目录" + EncodeResult + "完成");
        }