Ejemplo n.º 1
0
        public async Task <IActionResult> Detected([FromBody] ImageDetect imageDetect)
        {
            var ipEndPoint = new IPEndPoint(IPAddress.Parse(Ip), Port);

            var result = await _client.SendData(ipEndPoint, imageDetect.imageBase64);

            var encodingToString = Encoding.UTF7.GetString(result);

            return(Ok(encodingToString));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 将视频封面照,拿去百度检查
        /// </summary>
        private static void DetectFace2(int maxGetCount = 60 * 2 * 30) // 30分钟的数据)
        {
            var      baiduai      = new FaceDetect();
            int      i            = 0;
            DateTime nextCallTime = DateTime.Now;

            using (var db = DBSet.GetCon(DBSet.SqliteDBName.Bilibili))
            {
                foreach (var up in db.Select <UP>(o => o.follower > 3000).OrderByDescending(o => o.follower).ToArray())
                {
                    foreach (var av in db.Select <AV>(o => o.UpId == up.Id))
                    {
                        if (isExit)
                        {
                            break;
                        }

                        var pic = new Uri(av.pic).AbsolutePath.Replace("/", "_");

                        // 只按照本地文件名做验证
                        var detect = db.Single <ImageDetect>(o => o.LocalFile == pic);

                        if (detect == null)
                        {
                            byte[] bytes = null;

                            if (FromWeb)
                            {
                                try
                                {
                                    bytes = new WebClient().DownloadData(av.pic);
                                }
                                catch (Exception e)
                                {
                                    Console.WriteLine(e);
                                }
                            }
                            else
                            {
                                // 封面照落地,根据目前采集到数据,如果将宅舞区的封面照落地的话,估计要100多G
                                // 再加上三次元区,估计服务器硬盘干不动
                                var imagePath = SpiderConfig.GetPath($"imgs/{av.UpId}/{av.Id}");

                                var imageFile = Path.Combine(imagePath, pic);
                                if (!File.Exists(imageFile))
                                {
                                    continue;
                                }

                                bytes = File.ReadAllBytes(imageFile);
                            }

                            if (bytes == null)
                            {
                                continue;
                            }

                            var wait = (int)(nextCallTime - DateTime.Now).TotalMilliseconds + 1;

                            if (wait > 0)
                            {
                                Console.WriteLine($"wait {wait}");
                                Thread.Sleep(wait);
                            }

                            var start = DateTime.Now;
                            var ret   = baiduai.DetectFromBytes(bytes);
                            Console.Write($"useTime:{ (DateTime.Now - start).TotalMilliseconds} ms ");
                            nextCallTime = DateTime.Now.AddMilliseconds(500);

                            if (ret != null)
                            {
                                var dbItem = new ImageDetect
                                {
                                    AVId      = av.Id,
                                    UpId      = av.UpId,
                                    LocalFile = pic,
                                    Url       = av.pic,
                                    Detect    = ret.result,
                                };

                                if (ret.error_code == 0)
                                {
                                    dbItem.face_num = ret.result.face_num;
                                    if (ret.result.face_num > 0)
                                    {
                                        dbItem.max_face_probability = ret.result.face_list.Max(o => o.face_probability);
                                        dbItem.max_quality          = ret.result.face_list.Max(o => GetQuality(o));
                                    }
                                }

                                db.Insert(dbItem);

                                Console.WriteLine(av.title);
                                if (maxGetCount-- < 0)
                                {
                                    return;
                                }

                                // Thread.Sleep(500); // 百度的免费接口只有 2 qps,所以在这里做一下延迟。
                            }
                        }
                        else
                        {
                            // Console.WriteLine("忽略 " + av.title);
                        }
                    }
                }
            }
        }