/// <summary>
 ///     采用默认参数的跟踪定位和识别进行初始化
 /// </summary>
 /// <param name="appId">应用Id</param>
 /// <param name="locatorKey">定位Key</param>
 /// <param name="recognizeKey">识别Key</param>
 /// <param name="useTracking">是否使用跟踪</param>
 public FaceProcessor(string appId, string locatorKey, string recognizeKey, bool useTracking = false)
 {
     _locator = useTracking
         ? LocatorFactory.GetTrackingLocator(appId, locatorKey)
         : LocatorFactory.GetDetectionLocator(appId, locatorKey);
     _recognize = new FaceRecognize(appId, recognizeKey);
 }
Exemple #2
0
        private void Init()
        {
            _traking   = LocatorFactory.GetTrackingLocator(AppId, FtKey) as FaceTracking;
            _detection = LocatorFactory.GetDetectionLocator(AppId, FdKey) as FaceDetection;
            _recognize = new FaceRecognize(AppId, FrKey);
            _processor = new FaceProcessor(_traking, _recognize);

            //init cache
            if (Directory.Exists(FaceLibraryPath))
            {
                var files = Directory.GetFiles(FaceLibraryPath);
                foreach (var file in files)
                {
                    var info = new FileInfo(file);
                    _cache.Add(info.Name.Replace(info.Extension, ""), File.ReadAllBytes(file));
                }
            }

            CvInvoke.UseOpenCL = false;

            _capture = GetWebCamera();
            _capture.Start();

            //Application.Idle += VideoCaptured; //可以采用此方式捕获视频,则无需单独开线程
            //_capture.ImageGrabbed += VideoCaptured; //不要采用此方式
            _run = new Task(VideoCaptured);
            _run.Start();
        }
Exemple #3
0
        public void CLRGetFileNotExistThrow()
        {
            var loc = LocatorFactory.Create("clr-ns://UnitTest.Extension, Assembly = UnitTest.Extension");

            using (Stream s = loc.GetStream("log.xml", true))
            {
            }
        }
Exemple #4
0
        public void FSGetFileNotExistThrow()
        {
            var loc = LocatorFactory.Create(@"file:///..\..\");

            using (Stream s = loc.GetStream("log.xml", true))
            {
            }
        }
Exemple #5
0
        public void FSGetFileNotExist()
        {
            var loc = LocatorFactory.Create(@"file:///..\..\");

            using (Stream s = loc.GetStream("log.xml", false))
            {
                Assert.IsNull(s);
            }
        }
Exemple #6
0
        public void CLRGetResTest()
        {
            var loc = LocatorFactory.Create("clr-ns://UnitTest, Assembly = UnitTest.Extension");

            using (var s = loc.GetStream("Extension.res.txt"))
            {
                Assert.IsNotNull(s);
            }
        }
Exemple #7
0
        public void FSGetLogTest()
        {
            var loc = LocatorFactory.Create(@"file:///..\..\_ConfigFiles");

            using (Stream s = loc.GetStream("log.xml"))
            {
                Assert.IsNotNull(s);
            }
        }
Exemple #8
0
        public void CLRGetFileNotExist()
        {
            var loc = LocatorFactory.Create("clr-ns://UnitTest.Extension, Assembly = UnitTest.Extension");

            using (Stream s = loc.GetStream("log.xml", false))
            {
                Assert.IsNull(s);
            }
        }
Exemple #9
0
        private void Init()
        {
            _age       = new FaceAge(AppId, AgeKey);
            _gender    = new FaceGender(AppId, GenderKey);
            _traking   = LocatorFactory.GetTrackingLocator(AppId, FtKey, _age, _gender) as FaceTracking;
            _detection = LocatorFactory.GetDetectionLocator(AppId, FdKey) as FaceDetection;
            _recognize = new FaceRecognize(AppId, FrKey);
            _processor = new FaceProcessor(_traking, _recognize);

            //init cache
            if (Directory.Exists(FaceLibraryPath))
            {
                var files = Directory.GetFiles(FaceLibraryPath);
                foreach (var file in files)
                {
                    var info = new FileInfo(file);
                    _cache.Add(info.Name.Replace(info.Extension, ""), File.ReadAllBytes(file));
                }
            }

            stride     = width * pixelSize;
            bufferSize = stride * height;

            _pImage = Marshal.AllocHGlobal(bufferSize);
            _image  = new Bitmap(width, height, stride, PixelFormat.Format24bppRgb, _pImage);

            var ffmpeg = new FFMpegConverter();

            outputStream = new MemoryStream();

            var setting =
                new ConvertSettings
            {
                CustomOutputArgs = "-s 1920x1080", //根据业务需求-r参数可以调整,取决于摄像机的FPS
            };                                     //-s 1920x1080 -q:v 2 -b:v 64k

            //-an -r 15 -pix_fmt bgr24 -updatefirst 1
            //task = ffmpeg.ConvertLiveMedia("rtsp://*****:*****@192.168.1.64:554/h264/ch1/main/av_stream", null,
            //    outputStream, Format.raw_video, setting);

            /*
             * USB摄像头捕获
             * 通过ffmpeg可以捕获USB摄像,如下代码所示。
             * 首先通过:ffmpeg -list_devices true -f dshow -i dummy命令,可以列出系统中存在的USB摄像设备(或通过控制面板的设备管理工具查看设备名称),例如在我电脑中叫USB2.0 PC CAMERA。
             * 然后根据捕获的分辨率,修改视频图形信息,包括width和height,一般像素大小不用修改,如果要参考设备支持的分辨率,可以使用:
             * ffmpeg -list_options true -f dshow -i video="USB2.0 PC CAMERA"命令
             */
            task = ffmpeg.ConvertLiveMedia("video=Logitech HD Webcam C270", "dshow",
                                           outputStream, Format.raw_video, setting);

            task.OutputDataReceived += DataReceived;
            task.Start();

            _renderTask = new Task(Render);
            _renderTask.Start();
        }
Exemple #10
0
        public void FSCombineTest()
        {
            var loc = LocatorFactory.Create(@"file:///..\..\");

            loc = loc.Combine("_ConfigFiles");
            using (var s = loc.GetStream("log.xml"))
            {
                Assert.IsNotNull(s);
            }
        }
        /// <summary>
        /// 根据IP获取其所在地区
        /// </summary>
        /// <param name="str">地区名</param>
        /// <returns>返回IP,未查询到返回null</returns>
        public static string GetLocationByIp(this string str)
        {
            var ipRead = LocatorFactory.GetLocator(Locator.QQWry);
            var data   = ipRead.Query(str);

            if (data == null)
            {
                return(null);
            }

            return(data.Country);
        }
        public void TestMethod2()
        {
            var helper = LocatorFactory.GetLocator(Locator.QQWry);

            helper.Initiation();
            var ip = helper.Query("118.122.117.55");

            Assert.AreEqual("电信", ip.Local);
            Assert.AreEqual("四川省成都市", ip.Country);
            Assert.AreEqual("四川省", ip.Province);
            Assert.AreEqual("成都市", ip.City);
        }
        public void TestMethod6()
        {
            var helper = LocatorFactory.GetLocator(Locator.QQWry);

            helper.Initiation();
            var ip = helper.Query("1.4.4.255");

            //Assert.AreEqual("北龙中网(北京)科技有限责任公司", ip.Local);
            Assert.AreEqual("北京市海淀区", ip.Country);
            Assert.AreEqual("北京市", ip.Province);
            Assert.AreEqual("海淀区", ip.City);
        }
        public void TestMethod1()
        {
            var helper = LocatorFactory.GetLocator(Locator.QQWry);

            helper.Initiation();
            var ip = helper.Query("182.140.147.57");

            Assert.AreEqual("上海网宿科技股份有限公司电信CDN节点", ip.Local);
            Assert.AreEqual("四川省成都市", ip.Country);
            Assert.AreEqual("四川省", ip.Province);
            Assert.AreEqual("成都市", ip.City);
        }
Exemple #15
0
        public FaceDetectionService()
        {
            _age    = new FaceAge(AppConfigurations.AppId, AppConfigurations.AgeKey);        // 年龄识别
            _gender = new FaceGender(AppConfigurations.AppId, AppConfigurations.GenderKey);  // 性别识别
            //// 图片检测人脸
            _detection = LocatorFactory.GetDetectionLocator(AppConfigurations.AppId, AppConfigurations.FdKey, _age, _gender) as FaceDetection;
            _traking   = LocatorFactory.GetTrackingLocator(AppConfigurations.AppId, AppConfigurations.FtKey, _age, _gender) as FaceTracking;

            _recognize = new FaceRecognize(AppConfigurations.AppId, AppConfigurations.FrKey);

            _processor            = new FaceProcessor(_detection, _recognize);
            _personFaceRepository = new PersonFaceRepository();
        }
        public void TestMethod4()
        {
            //27.98.233.255   西藏拉萨市 联通
            var helper = LocatorFactory.GetLocator(Locator.QQWry);

            helper.Initiation();
            var ip = helper.Query("27.98.233.255");

            Assert.AreEqual("联通", ip.Local);
            Assert.AreEqual("西藏拉萨市", ip.Country);
            Assert.AreEqual("西藏", ip.Province);
            Assert.AreEqual("拉萨市", ip.City);
        }
        public void TestMethod3()
        {
            //1.15.255.255    北京市 北京北大方正宽带网络科技有限公司
            var helper = LocatorFactory.GetLocator(Locator.QQWry);

            helper.Initiation();
            var ip = helper.Query("1.15.255.255");

            Assert.AreEqual("北京北大方正宽带网络科技有限公司", ip.Local);
            Assert.AreEqual("北京市", ip.Country);
            Assert.AreEqual("北京市", ip.Province);
            Assert.AreEqual("北京市", ip.City);
        }
Exemple #18
0
        internal Localization(CultureInfo cInfo, ITargetLocator locator)
        {
            _cInfo = cInfo;

            if (locator == null)
            {
                _log.Warning("Locator pass to Localization is null, create default.");
                _locator = LocatorFactory.Create(LocalFilePath.LOCAL_FILE_SCHEME + Runtime.StartupDirectory);
            }
            else
            {
                _locator = locator;
            }
            _locator = _locator.Combine(L10N);
        }
Exemple #19
0
        public void CLREnumTest()
        {
            var loc   = LocatorFactory.Create("clr-ns://UnitTest,Assembly=UnitTest.Extension");
            var names = loc.EnumItems();

            var list = new List <string>()
            {
                "Extension.res.txt"
            };

            foreach (var name in names)
            {
                Assert.IsTrue(list.Contains(name));
            }
        }
Exemple #20
0
        public void FSEnumTest()
        {
            List <string> list = new List <string>()
            {
                "log.xml", "res.txt"
            };

            var loc   = LocatorFactory.Create(@"file:///..\..\_ConfigFiles\");
            var items = loc.EnumItems();

            foreach (var s in items)
            {
                Assert.IsTrue(list.Contains(s));
            }
        }
Exemple #21
0
        /// <summary>
        /// Uri can be file:/// or clr-ns://, see RexToy.Resources
        /// </summary>
        /// <param name="uri"></param>
        public static void SetResourceBase(string uri)
        {
            if (_locator != null)
            {
                _log.Warning("Localization resource base already set, can't switch.");
                return;
            }

            try
            {
                _locator = LocatorFactory.Create(uri);
            }
            catch
            {
                _log.Warning("Localization build locator with uri [{0}] fail.", uri);
                //Note: will pass null to Localization's constructor. it will handle null.
            }
        }
Exemple #22
0
        private static void TestAgeAndGender()
        {
            using (var detection = LocatorFactory.GetDetectionLocator("appid", "key"))
            {
                var image1 = Image.FromFile("test2.jpg");
                using (var estimate = new FaceAge("appid", "key"))
                {
                    var result1 = estimate.StaticEstimation(detection, new Bitmap(image1));
                    foreach (var result1Age in result1.Ages)
                    {
                        Console.WriteLine(result1Age);
                    }
                }

                using (var estimate = new FaceGender("appid", "key"))
                {
                    var result1 = estimate.StaticEstimation(detection, new Bitmap(image1));
                    foreach (var result1Gender in result1.Genders)
                    {
                        Console.WriteLine(result1Gender);
                    }
                }
            }

            //another
            var age    = new FaceAge("appid", "key");
            var gender = new FaceGender("appid", "key");

            using (var detection = LocatorFactory.GetDetectionLocator("appid", "key", age, gender))
            {
                var image1 = Image.FromFile("test2.jpg");
                var result = detection.Detect(new Bitmap(image1), out var location,
                                              LocateOperation.IncludeAge | LocateOperation.IncludeGender); //default is None, no age and gender estimation
                for (var i = 0; i < location.FaceCount; i++)
                {
                    Console.WriteLine(location.Ages[i]);
                    Console.WriteLine(location.Genders[i]);
                }
            }
            age.Dispose();
            gender.Dispose();
        }
Exemple #23
0
        private void Init()
        {
            _traking   = LocatorFactory.GetTrackingLocator(AppId, FtKey) as FaceTracking;
            _detection = LocatorFactory.GetDetectionLocator(AppId, FdKey) as FaceDetection;
            _recognize = new FaceRecognize(AppId, FrKey);
            _processor = new FaceProcessor(_traking, _recognize);

            //init cache
            if (Directory.Exists(FaceLibraryPath))
            {
                var files = Directory.GetFiles(FaceLibraryPath);
                foreach (var file in files)
                {
                    var info = new FileInfo(file);
                    _cache.Add(info.Name.Replace(info.Extension, ""), File.ReadAllBytes(file));
                }
            }

            _pImage = Marshal.AllocHGlobal(1920 * 1080 * 3);
            _image  = new Bitmap(1920, 1080, 1920 * 3, PixelFormat.Format24bppRgb, _pImage);

            var ffmpeg = new FFMpegConverter();

            outputStream = new MemoryStream();

            var setting =
                new ConvertSettings
            {
                CustomOutputArgs = "-an -r 15 -pix_fmt bgr24 -updatefirst 1" //根据业务需求-r参数可以调整,取决于摄像机的FPS
            };                                                               //-s 1920x1080 -q:v 2 -b:v 64k

            task = ffmpeg.ConvertLiveMedia("rtsp://*****:*****@192.168.1.64:554/h264/ch1/main/av_stream", null,
                                           outputStream, Format.raw_video, setting);

            task.OutputDataReceived += DataReceived;
            task.Start();

            _renderTask = new Task(Render);
            _renderTask.Start();
        }
Exemple #24
0
        private static void TestDetection()
        {
            using (var detection = LocatorFactory.GetDetectionLocator("appId", "sdkKey"))
            {
                var image  = Image.FromFile("test.jpg");
                var bitmap = new Bitmap(image);

                var result = detection.Detect(bitmap, out var locateResult);
                using (locateResult)
                {
                    if (result == ErrorCode.Ok && locateResult.FaceCount > 0)
                    {
                        using (var g = Graphics.FromImage(bitmap))
                        {
                            var face = locateResult.Faces[0].ToRectangle();
                            g.DrawRectangle(new Pen(Color.Chartreuse), face.X, face.Y, face.Width, face.Height);
                        }

                        bitmap.Save("output.jpg", ImageFormat.Jpeg);
                    }
                }
            }
        }
Exemple #25
0
        private static void Test()
        {
            using (var detection = LocatorFactory.GetTrackingLocator("appid",
                                                                     "sdkKey"))
            {
                var image1 = new Bitmap(Image.FromFile("test.jpg"));
                var image2 = new Bitmap(Image.FromFile("test3.jpg"));
                var image3 = new Bitmap(Image.FromFile("test3.jpg"));
                var image4 = new Bitmap(Image.FromFile("test4.jpg"));


                var r1 = detection.Detect(new Bitmap(image1), out var l1);

                var r2 = detection.Detect(new Bitmap(image2), out var l2);

                var r3 = detection.Detect(new Bitmap(image3), out var l3);

                var r4 = detection.Detect(new Bitmap(image4), out var l4);

                using (var g = Graphics.FromImage(image2))
                {
                    foreach (var s in l2.Faces)
                    {
                        var face = s.ToRectangle();
                        g.DrawRectangle(new Pen(Color.Chartreuse), face.X, face.Y, face.Width, face.Height);
                    }
                }

                image2.Save("output.jpg", ImageFormat.Jpeg);

                l1.Dispose();
                l2.Dispose();
                l3.Dispose();
                l4.Dispose();
            }
        }