Last active
August 29, 2015 14:02
-
-
Save 0V/cacdfcb40406f22ab500 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Text; | |
using System.Diagnostics; | |
using System.IO; | |
using OpenCvSharp; | |
using OpenCvSharp.CPlusPlus; | |
namespace CaptureTest | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
// Webカメラから画像を取り込んでMatに変換する時に、どの方法が早いかをテスト | |
Cv1Capture(10); | |
Cv2Capture(10); | |
} | |
public static void Cv1Capture(int count, string fileName = "Cv1Capture.txt") | |
{ | |
using (var writer = new StreamWriter(fileName, true, Encoding.GetEncoding("utf-8"))) | |
{ | |
for (int i = 0; i < count; i++) | |
{ | |
var sw = new Stopwatch(); | |
sw.Start(); | |
var capture = Cv.CreateCameraCapture(0); | |
for (int k = 0; k < 100; k++) | |
{ | |
var frame = capture.QueryFrame(); | |
Cv2.ImShow("Capture", Cv2.CvArrToMat(frame)); | |
Cv.WaitKey(5); | |
} | |
sw.Stop(); | |
Console.WriteLine(sw.ElapsedMilliseconds); | |
writer.WriteLine(sw.ElapsedMilliseconds.ToString()); | |
} | |
} | |
} | |
public static void Cv2Capture(int count, string fileName = "Cv2Capture.txt") | |
{ | |
using (var writer = new StreamWriter(fileName, true, Encoding.GetEncoding("utf-8"))) | |
{ | |
var frame = new Mat(); | |
for (int i = 0; i < count; i++) | |
{ | |
var sw = new Stopwatch(); | |
sw.Start(); | |
var capture = Cv2.CreateFrameSource_Camera(0); | |
for (int k = 0; k < 100; k++) | |
{ | |
capture.NextFrame(frame); | |
Cv2.ImShow("Capture", frame); | |
Cv.WaitKey(5); | |
} | |
sw.Stop(); | |
Console.WriteLine(sw.ElapsedMilliseconds); | |
writer.WriteLine(sw.ElapsedMilliseconds.ToString()); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment