public void DrawDLInVedio(String videoFile, String outputFile, String targetFile, String indexFile, int fileoffset, Scalar color) { VideoCapture capture = new VideoCapture(videoFile); Mat image = new Mat(); OpenCvSharp.CPlusPlus.Size dsize = new OpenCvSharp.CPlusPlus.Size(capture.FrameWidth, capture.FrameHeight); VideoWriter writer = new VideoWriter(outputFile, FourCC.MJPG, fps, dsize, true); int k = 0; List <string> targetList = IOTools.ReadListFromTxt(targetFile); List <string> indexList = IOTools.ReadListFromTxt(indexFile); int t = 0; String status = " "; while (capture.Read(image)) { String[] ss = targetList[t + fileoffset].Split(' '); if (t < indexList.Count - 2 && k == int.Parse(indexList[t + 1])) { t++; } Cv2.Circle(image, (int)double.Parse(ss[0]), (int)double.Parse(ss[1]), 10, color, 2 ); // Cv2.PutText(image, status, // new Point((int)double.Parse(ss[0]) - 5, (int)double.Parse(ss[1])), FontFace.Italic, 1, color, 3); if (t > 5) { String[] ssPre = targetList[t + fileoffset - 5].Split(' '); if (double.Parse(ss[1]) - double.Parse(ssPre[1]) < -25) { status = "Pick Up"; } else if (double.Parse(ss[1]) - double.Parse(ssPre[1]) > 30) { status = "Put Down"; } else if (Math.Abs(double.Parse(ss[1]) - double.Parse(targetList[fileoffset].Split(' ')[1])) < 10) { status = " "; } } //if (double.Parse(ss[1]) < 420) writer.Write(image); k++; } ; writer.Release(); }
public void DrawParticlesInVedio(String videoFile, String outputFile, String particlefile, String resultFile) { VideoCapture capture = new VideoCapture(videoFile); Mat image = new Mat(); OpenCvSharp.CPlusPlus.Size dsize = new OpenCvSharp.CPlusPlus.Size(capture.FrameWidth, capture.FrameHeight); VideoWriter writer = new VideoWriter(outputFile, FourCC.MJPG, fps, dsize, true); int k = 0; List <string> targetList = IOTools.ReadListFromTxt(resultFile); List <string> particleList = IOTools.ReadListFromTxt(particlefile); int t = 0; String status = " "; while (capture.Read(image)) { if (t >= targetList.Count) { break; } String[] ss = targetList[t].Split(' '); for (int i = 0; i < 100; i++) { String[] pp = particleList[t * 100 + i].Split(' '); Cv2.Circle(image, (int)double.Parse(pp[0]), (int)double.Parse(pp[1]), 1, new Scalar(255, 0, 0), 2 ); } Cv2.Circle(image, (int)double.Parse(ss[0]), (int)double.Parse(ss[1]), 10, new Scalar(255, 255, 0), 2 ); // Cv2.PutText(image, status, // new Point((int)double.Parse(ss[0]) - 5, (int)double.Parse(ss[1])), FontFace.Italic, 1, color, 3); //if (double.Parse(ss[1]) < 420) writer.Write(image); t++; } ; writer.Release(); }