-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathVideo3.cs
76 lines (48 loc) · 2.13 KB
/
Video3.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using System;
using Emgu.CV;
using Emgu.CV.Structure;
using Emgu.CV.Util;
namespace myNamespace
{
class Program
{
/* static void Main(string[] args)
{
Mat pic = CvInvoke.Imread("./img/dog.jpg");
Mat gaussianBlur = new Mat();
Mat sobelX = new Mat();
Mat sobelY = new Mat();
Mat sobelXY = new Mat();
pic.CopyTo(sobelX);
pic.CopyTo(sobelY);
pic.CopyTo(sobelXY);
CvInvoke.GaussianBlur(pic, gaussianBlur, new System.Drawing.Size(3,3), 5.0);
CvInvoke.Sobel(gaussianBlur, sobelX, Emgu.CV.CvEnum.DepthType.Default, 1, 0, 5);
CvInvoke.Sobel(gaussianBlur, sobelY, Emgu.CV.CvEnum.DepthType.Default, 0, 1, 5);
CvInvoke.Sobel(gaussianBlur, sobelXY, Emgu.CV.CvEnum.DepthType.Default, 1, 1, 5);
//CvInvoke.Imshow("sobelX", sobelX);
//CvInvoke.Imshow("sobelY", sobelY);
//CvInvoke.Imshow("sobelXY", sobelXY);
//CvInvoke.WaitKey();
Mat cannyPic = new Mat();
var average = pic.ToImage<Gray, byte>().GetAverage();
var lowerthreshold = Math.Max(0, (1.0 - 0.33) * average.Intensity);
var upperthreshold = Math.Max(255, (1.0 + 0.33) * average.Intensity);
CvInvoke.Canny(gaussianBlur, cannyPic, lowerthreshold, upperthreshold, 3);
//CvInvoke.Imshow("canny", cannyPic);
//CvInvoke.WaitKey();
Mat iphone = CvInvoke.Imread("./img/iphone.jpg");
VectorOfVectorOfPoint contours = new VectorOfVectorOfPoint();
Mat thresholdPic = new Mat();
Mat hierarchy = new Mat();
Image<Gray, byte> grayPhone = iphone.ToImage<Gray, byte>();
CvInvoke.Threshold(grayPhone, thresholdPic, 210, 255, Emgu.CV.CvEnum.ThresholdType.Binary);
CvInvoke.Imshow("threshold", thresholdPic);
CvInvoke.FindContours(thresholdPic, contours, hierarchy, Emgu.CV.CvEnum.RetrType.Tree, Emgu.CV.CvEnum.ChainApproxMethod.ChainApproxNone);
//CvInvoke.DrawContours(iphone, contours, -1, new MCvScalar(0,255,0), 2);
CvInvoke.FillPoly(iphone, contours, new MCvScalar(255, 100, 100));
CvInvoke.Imshow("iphone", iphone);
CvInvoke.WaitKey();
}*/
}
}