Пример #1
0
        public CaptureData()
        {
            CapturedMotionData = new MotionData
            {
                Angles = null,
                MotionPixelCountArray = null,
                OverallAngle = 0.0,
                OverallMotionPixelCount = 0.0,
                Rects = null
            };

            MotionImage = new Mat();
            CapturedImage = new Mat();
            ForegroundImage = new Mat();
        }
Пример #2
0
        public static double CalculateScore(MotionData[] destData, MotionData[] origData)
        {
            double totalScore = 0.0;
            int scoreCount = 0;
            int motivationDataLength = Math.Min(destData.Length, origData.Length);
            for (int i = 1; i < motivationDataLength; i++)
            {
                double overallAngleScore = Math.Abs(ReverseAngle(destData[i].OverallAngle) - ReverseAngle(origData[i].OverallAngle));

                int destArrayLength = destData[i].Angles.Length;

                double destScore = 0.0;
                int matchedData = 0;
                for (int j = 0; j < destArrayLength; j++)
                {
                    double area = destData[i].Rects[j].Height * destData[i].Rects[j].Width;
                    if (destData[i].MotionPixelCountArray[j] < area * Constants.MIN_MOTION_PIXEL_RATIO_IN_AN_AREA)
                        continue;

                    double areaAngleScore = CalcSimilarAreaFromOrigData(destData[i].Rects[j], destData[i].Angles[j], origData, i, Constants.FIND_RANGE);

                    //Do not find good area.
                    if (areaAngleScore < 0)
                        continue;

                    destScore += areaAngleScore;
                    matchedData++;
                }
                //totalScore += matchedData*(1/(destScore + 1) + 2 * 1/(overallAngleScore + Constants.DEGREE_OF_SEMI_CIRCLE * 2));
                if (matchedData > 0)
                {
                    totalScore += (overallAngleScore) * 0 + destScore / matchedData * 1;
                    scoreCount ++;
                }
            }

            return totalScore / scoreCount;
        }
Пример #3
0
        private static double CalcSimilarAreaFromOrigData(Rectangle destRect, double destAngle, MotionData[] origData, int index, int findRange = 3)
        {
            double areaAngleScore = 0.0;

            if (origData.Length == 0)
                return -1;

            if (index > origData.Length)
                return -1;

            if (destRect.Width == 0 || destRect.Height == 0)
                return -1;

            int firstIndex = Math.Max(1, index - findRange);
            int lastIndex = Math.Min(index + findRange, origData.Length);

            for(int i = firstIndex; i < lastIndex; i++)
            {
                int origArrayLength = origData[i].Angles.Length;
                int matchedArea = 0;
                double angleScore = 0;
                for (int j = 0; j < origArrayLength; j++)
                {
                    double area = origData[i].Rects[j].Height * origData[i].Rects[j].Width;
                    if (origData[i].MotionPixelCountArray[j] < area * Constants.MIN_MOTION_PIXEL_RATIO_IN_AN_AREA)
                        continue;

                    if (!IsSimilarRectArea(origData[i].Rects[j], destRect, Constants.SIMILAR_AREA_THRESHOLD))
                        continue;

                    //If find a rect matched, calculate and break, then find next rect
                    angleScore += Math.Abs(ReverseAngle(destAngle) - ReverseAngle(origData[i].Angles[j]));

                     //Found area count +1
                    matchedArea++;
                }

                if (matchedArea > 0)
                    areaAngleScore += angleScore / matchedArea;
            }

            return areaAngleScore;
        }
Пример #4
0
 private void WriteOrigData(MotionData md)
 {
     if (!IsDisposed && !Disposing && InvokeRequired)
     {
         Invoke((Action<MotionData>)WriteOrigData, md);
     }
     else
     {
         var settings = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore };
         string json = JsonConvert.SerializeObject(md, Formatting.None, settings);
         if (_db.IsConnected(Constants.REDIS_KEY_OIRG_DATA))
             _db.StringAppend(Constants.REDIS_KEY_OIRG_DATA, json + Constants.REDIS_SEPERATE_SYMBOL);
     }
 }
Пример #5
0
        private void GradeButton_Click(object sender, EventArgs e)
        {
            _redis = ConnectionMultiplexer.Connect(_redisHost);

            if (_redis == null)
                return;

            _db = _redis.GetDatabase();

            if (_db == null)
                return;

            RedisValue capturedRv= _db.StringGet(Constants.REDIS_KEY_CAPTURED_DATA);
            RedisValue origRv = _db.StringGet(Constants.REDIS_KEY_OIRG_DATA);

            string[] capturedDataArr = capturedRv.ToString()
                .Split(Constants.REDIS_SEPERATE_SYMBOL.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            string[] origDataArr = origRv.ToString()
                .Split(Constants.REDIS_SEPERATE_SYMBOL.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

            /*
            using (FileStream fs = new FileStream("d:\\temp\\Orig.data", FileMode.OpenOrCreate))
            {
                byte[] data = new UTF8Encoding().GetBytes(origRv);
                fs.Write(data, 0, data.Length);
                fs.Flush();
                fs.Close();
            }

            using (FileStream fs = new FileStream("d:\\temp\\Capt.data", FileMode.OpenOrCreate))
            {
                byte[] data = new UTF8Encoding().GetBytes(capturedRv);
                fs.Write(data, 0, data.Length);
                fs.Flush();
                fs.Close();
            }
            */

            var settings = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore };

            MotionData[] capturedData = new MotionData[capturedDataArr.Length];
            int capturedCounter = 0;
            foreach (var str in capturedDataArr)
            {
                capturedData[capturedCounter] = JsonConvert.DeserializeObject<MotionData>(str, settings);
                capturedCounter++;
            }

            MotionData[] origData = new MotionData[origDataArr.Length];
            int origCounter = 0;
            foreach (var str in origDataArr)
            {
                origData[origCounter] = JsonConvert.DeserializeObject<MotionData>(str, settings);
                origCounter++;
            }

            double score = Constants.MAX_SCORE - ProcessVideo.CalculateScore(capturedData, origData);
            ScoreLabel.Text = "得分: " + score.ToString();

            //Clear db
            _db.StringSet(Constants.REDIS_KEY_CAPTURED_DATA, "");
            _db.StringSet(Constants.REDIS_KEY_OIRG_DATA, "");
        }