コード例 #1
0
ファイル: YuvVideoHandlerTest.cs プロジェクト: PSE-2012/MMWTV
        public void getFrameTest()
        {
            YuvVideoInfo info = new YuvVideoInfo();
            info.height = 144;
            info.width = 176;
            info.yuvFormat = YuvFormat.YUV420_IYUV;
            YuvVideoHandler target = new YuvVideoHandler();
            target.setVideo(TESTVIDEO_PATH, info);

            Bitmap expected = null;
            Bitmap actual;

            TestContext.BeginTimer("frame1");
            actual = target.getFrame(0);
            TestContext.EndTimer("frame1");

            TestContext.BeginTimer("frame2");
            actual = target.getFrame(1);
            TestContext.EndTimer("frame2");

            //TODO: How to compare this?!

            Assert.Inconclusive("Implement some way to check result first.");
        }
コード例 #2
0
ファイル: YuvVideoHandlerTest.cs プロジェクト: PSE-2012/MMWTV
        public void readANDwriteFrameTest()
        {
            //init handler to read sample file
            YuvVideoInfo info_r = new YuvVideoInfo();
            info_r.height = 144;
            info_r.width = 176;
            info_r.yuvFormat = YuvFormat.YUV420_IYUV;
            YuvVideoHandler reader = new YuvVideoHandler();
            reader.setVideo(TESTVIDEO_PATH, info_r);

            //init handler to write a copy of sample file
            YuvVideoInfo info_w = new YuvVideoInfo();
            info_w.height = 144;
            info_w.width = 176;
            info_w.yuvFormat = YuvFormat.YUV420_IYUV;
            YuvVideoHandler writer = new YuvVideoHandler();
            writer.setVideo(TESTVIDEO_PATH + "copy", info_w);

            //copy sample file frame by frame
            //REMARK: This part can be commented out to save time once the copy is written to disk
            //          if this test is run several times to tweak parameters and error calculations
            for (int j = 0; j < ((YuvVideoInfo)reader.vidInfo).frameCount; j++)
            {
                Bitmap bmp = reader.getFrame(j);

                writer.writeFrame(j, bmp);
            }

            //
            //compare original file with the copy read and written by the handler
            //
            //TODO: Debug writeFrame() & getFrame() as there are significant differences when a copy of a file is created through YuvVideoHandlers

            //set buffersize to one frame
            int bsize =(int)( info_r.width * info_r.height * (1 + YuvVideoHandler.getLum2Chrom(info_r.yuvFormat)) );

            int error = 0;
            int errorcount = 0;

            FileStream fs1;
            fs1 = new FileStream(TESTVIDEO_PATH, FileMode.Open);
            byte[] data1 = new byte[bsize];
            FileStream fs2;
            fs2 = new FileStream(TESTVIDEO_PATH+"copy", FileMode.Open);
            byte[] data2 = new byte[bsize];

            //log files are written to the log folder with error information about frames and the whole file
            //because an unfulfilled assertion cancels the whole testrun
            StreamWriter log = new StreamWriter("C:/Dokumente und Einstellungen/Sebastian/Eigene Dateien/PSE/Implementierung/YuvVideoHandler/log/log.txt");

            //compare original and copy bytewise
            for (int i = 0; i < fs1.Length; i += bsize)
            {
                int r = fs1.Read(data1, 0, bsize);
                int r2 = fs2.Read(data2, 0, bsize);

                Assert.AreEqual(r, r2, "file read out of sync");

                //init log writer for this frame
                //the logfile of each frame contains the difference in value of original and copy for each byte
                //the diffs are written in the textfile as a matrix according to pixel position
                StreamWriter logdetail = new StreamWriter("C:/Dokumente und Einstellungen/Sebastian/Eigene Dateien/PSE/Implementierung/YuvVideoHandler/log/log"+(i/bsize)+".txt");

                for (int j = 0; j < r; j++)
                {
                    int diff = Math.Abs(data1[j] - data2[j]);

                    int y = j / info_r.width;
                    int x = j % info_r.width;

                    if (j % info_r.width == 0) logdetail.Write(logdetail.NewLine);

                    //Assert.IsTrue(diff < 5, "big difference at "+x+","+y+": "+diff);
                    logdetail.Write(diff+" ");
                    error += diff;
                    if (diff > 5) errorcount++;

                }

                logdetail.Close();

                //the global logfile is written with the accumulated information about this frame
                float errorratio = (((float)errorcount) / bsize);
                log.WriteLine("Frame: "+(i/bsize)+" / errorratio: "+errorratio);
                //Assert.IsTrue(error < 10, i+": error ratio: " + errorratio + " / error count: " + errorcount + " / accumulated error: " + error);

                error = 0;
                errorcount = 0;
            }

            log.Close();

            fs1.Close();
            fs2.Close();

            Assert.Inconclusive("Compare logfiles to determine errorrates");
        }
コード例 #3
0
ファイル: VideoHandlerTest.cs プロジェクト: PSE-2012/MMWTV
 public void flushWriterTest()
 {
     YuvVideoHandler yvh = new YuvVideoHandler();
     YuvVideoInfo info = new YuvVideoInfo(readPath);
     info.width = 352;
     info.height = 240;
     info.yuvFormat = YuvFormat.YUV420_IYUV;
     yvh.setReadContext(readPath, info); // write context cannot be set without a valid read context
     writePath = sampleVideosPath + "\\americanFootball_352x240_125_Copy.yuv";
     YuvVideoInfo writeinfo = new YuvVideoInfo();
     writeinfo.path = writePath;
     writeinfo.width = 352;
     writeinfo.height = 240;
     writeinfo.yuvFormat = YuvFormat.YUV420_IYUV;
     yvh.setWriteContext(writePath, writeinfo);
     int oldFrameByteSize = yvh.frameByteSize;
     yvh.flushWriter();
     Assert.AreEqual(oldFrameByteSize, yvh.frameByteSize);
     Assert.AreEqual(0, yvh.positionReader);
     System.Drawing.Bitmap testframe = yvh.getFrame();
     System.Drawing.Bitmap[] frames = new System.Drawing.Bitmap[1];
     frames[0] = testframe;
     yvh.writeFrames(4, frames);
     yvh.flushWriter();
     yvh.writeFrames(4, frames);
 }