Esempio n. 1
0
        public Form1()
        {
            InitializeComponent();
            // プロパティ > ビルド > プラットフォームターゲット > x64 でビルドしてください
            ClearMessage();
            var model = LoadModel(_modelPath);

            _yolo        = model.Item1;
            _aspectRatio = model.Item2;

            foreach (var b in Enum.GetValues(typeof(Backend)))
            {
                this.comboBoxBackend.Items.Add(b.ToString());
            }
            this.comboBoxBackend.SelectedIndex = 0;
            this.comboBoxBackend.Enabled       = true;


            foreach (var t in Enum.GetValues(typeof(Target)))
            {
                this.comboBoxTarget.Items.Add(t.ToString());
            }
            this.comboBoxTarget.SelectedIndex = 0;
            this.comboBoxTarget.Enabled       = true;
        }
Esempio n. 2
0
 public INewCEPExpression <InputType> Branch <InputType>(out INewCEPExpression <InputType> expr)
 {
     expr = Yolo.Express <InputType>();
     this.Attach(expr);
     return(new NewAbstractCEPExpression <InputType>(this.InputBlock, this.OutputBlock));
     //return new NewAbstractCEPExpression<InputType>();
 }
Esempio n. 3
0
        public Form1()
        {
            InitializeComponent();
            // プロパティ > ビルド > プラットフォームターゲット > x64 でビルドしてください
            ClearMessage();
            var model = LoadModel(_modelPath);

            _yolo        = model.Item1;
            _aspectRatio = model.Item2;

            foreach (var b in Enum.GetValues(typeof(Backend)))
            {
                this.comboBoxBackend.Items.Add(b.ToString());
            }
            this.comboBoxBackend.SelectedIndex = 0;
            this.comboBoxBackend.Enabled       = true;


            foreach (var t in Enum.GetValues(typeof(Target)))
            {
                this.comboBoxTarget.Items.Add(t.ToString());
            }
            this.comboBoxTarget.SelectedIndex = 0;
            this.comboBoxTarget.Enabled       = true;

            // NMS init
            confidence_thresh = (float)this.num_confidence.Value;
            nms_thresh        = (float)this.num_nms.Value;
            use_NMS           = this.cbxUseNMS.Checked;
        }
Esempio n. 4
0
 /// <summary>
 /// Initializes a new Darknet detector with the <paramref name="cfgFile"/> and the <paramref name="weightFile"/>
 /// </summary>
 /// <param name="cfgFile">The *.cfg file</param>
 /// <param name="weightFile">The *.weights file</param>
 /// <param name="instanceNumber">The instance of YoloApi.dll to avoid static detector limitation from darknet c++ library. A file with the name YoloApi{instancenumber}.dll is needed</param>
 /// <param name="gpuId">The index of a CUDA compatible GPU</param>
 /// <param name="cudaVersion">Cuda version, 10 or 11, by default 10</param>
 public Darknet(string cfgFile, string weightFile, int instanceNumber, int gpuId, int cudaVersion)
 {
     if (instanceNumber > 3 || instanceNumber < 0)
     {
         throw new ArgumentException("instanceNumber must be  0 <= and <= 3");
     }
     _yolo = new Yolo(cfgFile, weightFile, gpuId, instanceNumber, cudaVersion);
 }
 public HCaptcha(string site, bool yolo, bool headless = false)
 {
     Site     = site;
     Headless = headless;
     if (yolo)
     {
         Yolo = new Yolo();
         Yolo.Setup();
     }
     Random = new Random();
 }
Esempio n. 6
0
        public static void RunDetection()
        {
            var net      = YOLOV3.YOLO3_Darknet53_VOC(pretrained: true);
            var im_fname = Utils.Download("https://raw.githubusercontent.com/zhreshold/mxnet-ssd/master/data/demo/dog.jpg", "objdet.jpg");

            var(x, img) = Yolo.LoadTest(im_fname, @short: 512);
            Img.ImShow(x);
            Console.WriteLine("Shape of pre-processed image:" + x.Shape);
            var(class_IDs, scores, bounding_boxs) = net.Call(x.AsType(DType.Float32));
            img = Viz.PlotBBox(img, bounding_boxs[0], scores[0], class_IDs[0], class_names: net.Classes);
            Img.ImShow(img);
        }
Esempio n. 7
0
        public static void Main(string[] args)
        {
            var p = new Processor(2, 1);


            //Yolo.Manager.Register("example1", 0);
            var expr1 = Yolo.Express <int>().Where(x => x > 5).Perform(x => System.Console.WriteLine(x));

            //.Manager.Get("example1").Attach(expr1);
            expr1.Send(10);

            expr1.Send(4);
        }
Esempio n. 8
0
        public bool LoadModel(string modelPath)
        {
            ModelPath model = new ModelPath(modelPath);

            _aspectRatio = model.FixedAspectRatio;
            if (model.Found)
            {
                _yolo       = new Yolo(model.ConfigPath, model.WeightsPath, model.NamesPath);
                IsYoloReady = true;
            }
            else
            {
                MessageBox.Show("Missing Required model(.cfg, .weight, .name) files", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);

                IsYoloReady = false;
            }
            return(IsYoloReady);
        }
        public Tuple <Yolo, float> LoadModel(string modelPath)
        {
            ModelPath model = new ModelPath(modelPath);

            _aspectRatio = model.FixedAspectRatio;
            if (model.Found)
            {
                _yolo = new Yolo(model.ConfigPath, model.WeightsPath, model.NamesPath);
                //string processName = Path.GetFileNameWithoutExtension(Process.GetCurrentProcess().MainModule.FileName);
                //string title = $"{Path.GetFileNameWithoutExtension(model.NamesPath)} - {processName}";
                //this.Text = title;
                //AppendMessage($"{model.ConfigPath},{model.WeightsPath},{model.NamesPath} を読み込みました。\r\n画像を Drag&Drop してください。");
            }
            else
            {
                MessageBox.Show("Missing Required model(.cfg, .weight, .name) files", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(Tuple.Create <Yolo, float>(_yolo, _aspectRatio));
        }
Esempio n. 10
0
        private void LoadModel(string modelPath)
        {
            ModelPath model = new ModelPath(modelPath);

            _aspectRatio = model.FixedAspectRatio;
            ClearMessage();
            if (model.Found)
            {
                _yolo = new Yolo(model.ConfigPath, model.WeightsPath, model.NamesPath);
                this.pictureBox1.AllowDrop = true;
                string processName = Path.GetFileNameWithoutExtension(Process.GetCurrentProcess().MainModule.FileName);
                string title       = $"{Path.GetFileNameWithoutExtension(model.NamesPath)} - {processName}";
                this.Text = title;
                AppendMessage($"{model.ConfigPath},{model.WeightsPath},{model.NamesPath} を読み込みました。\r\n画像を Drag&Drop してください。");
            }
            else
            {
                AppendMessage($"ファイルが見つかりませんでした。{_modelPath} フォルダに .cfg, .weights, .names ファイルを1つずつ配置してください。");
            }
        }
        public async Task <bool> SolveCaptcha()
        {
            Console.WriteLine("[!] Navigating [!]");
            await new BrowserFetcher().DownloadAsync();
            var browser = await Puppeteer.LaunchAsync(new LaunchOptions
            {
                Headless = Headless,
                Args     = new string[]
                {
                    "--start-maximized"
                }
            });

            Browser = browser;
            var page = await browser.NewPageAsync();

            page.RequestFinished += Page_RequestFinished;
            await page.SetViewportAsync(new ViewPortOptions
            {
                Width  = 1920 / 2,
                Height = 1080
            });

            await page.GoToAsync(Site);

            await page.WaitForSelectorAsync("iframe[src^='https://newassets.hcaptcha.com/captcha/v1/']");

            await page.WaitForTimeoutAsync(5000);

            Console.WriteLine("[!] Collecting frames [!]");
            var checkbox  = page.Frames.Where(x => x.Url.Contains("hcaptcha-checkbox.html")).First();
            var challenge = page.Frames.Where(x => x.Url.Contains("hcaptcha-challenge.html")).First();

            Console.WriteLine("[!] Checking box [!]");
            await checkbox.ClickAsync("#checkbox");

            Console.WriteLine("[!] Waiting for challenge frame to show [!]");
            await page.WaitForTimeoutAsync(5000);

            var text = await challenge.EvaluateExpressionAsync("document.querySelector('body > div.challenge-container > div > div > div.challenge-header > div.challenge-prompt > div.prompt-padding > div.prompt-text').innerHTML");

            var thing  = text.ToString().Split(' ').Last().Replace("motorbus", "bus").Replace("airplane", "aeroplane");
            var crumbs = await challenge.EvaluateExpressionAsync("document.querySelector('body > div.challenge-interface > div.challenge-breadcrumbs > div').children.length");

            if (Convert.ToInt32(crumbs) == 0)
            {
                return(await SolveCaptcha()); //sometimes this happens :/
            }
            Console.WriteLine($"[!] We are looking for: {thing} [!]");
            Console.WriteLine($"[!] Crumbs: {crumbs} [!]");
            for (var x = 0; x < Convert.ToInt32(crumbs.ToString()); x++)
            {
                var imageurls = new List <string>();

                for (var i = 1; i < 10; i++)
                {
                    var image = await challenge.EvaluateExpressionAsync($"document.querySelector('body > div.challenge-container > div > div > div.task-grid > div:nth-child({i}) > div.image-wrapper > div').style.background.replace('url(\"', '').replace('\")', '').split(' ')[0].replace(' ', '')");

                    imageurls.Add(image.ToString());
                }

                var j = 0;
                foreach (var imageurl in imageurls)
                {
                    j++;
                    if (Yolo == null)
                    {
                        var response     = await new HttpClient().GetAsync($"https://www.imageidentify.com/objects/user-26a7681f-4b48-4f71-8f9f-93030898d70d/prd/urlapi?image={HttpUtility.UrlEncode(imageurl)}");
                        var json         = JObject.Parse(response.Content.ReadAsStringAsync().Result);
                        var identify     = json.GetValue("identify").ToObject <JObject>();
                        var alternatives = identify.GetValue("alternatives").ToObject <JObject>();
                        var title        = identify.GetValue("title").ToString();

                        if (title.ToLower().Contains(thing))
                        {
                            Console.WriteLine("[!] CLICKED FROM TITLE [!]");
                            await challenge.ClickAsync($"body > div.challenge-container > div > div > div.task-grid > div:nth-child({j}) > div.image-wrapper > div");

                            continue;
                        }

                        foreach (var what in alternatives.Children())
                        {
                            var property = what.ToObject <JProperty>();
                            var yep      = false;

                            if (property.Name.ToLower().Contains(thing) && property.Value.ToString().ToLower().Contains(thing))
                            {
                                Console.WriteLine("[!] CLICKED FROM PROPERTY NAME AND VALUE [!]");
                                await challenge.ClickAsync($"body > div.challenge-container > div > div > div.task-grid > div:nth-child({j}) > div.image-wrapper > div");

                                yep = true;
                                continue;
                            }

                            if (property.Name.ToLower().Contains(thing) && !yep)
                            {
                                Console.WriteLine("[!] CLICKED FROM PROPERTY NAME [!]");
                                await challenge.ClickAsync($"body > div.challenge-container > div > div > div.task-grid > div:nth-child({j}) > div.image-wrapper > div");

                                yep = true;
                                continue;
                            }

                            if (property.Value.ToString().ToLower().Contains(thing) && !yep)
                            {
                                Console.WriteLine("[!] CLICKED FROM PROPERTY VALUE [!]");
                                await challenge.ClickAsync($"body > div.challenge-container > div > div > div.task-grid > div:nth-child({j}) > div.image-wrapper > div");

                                yep = true;
                                continue;
                            }
                        }
                    }
                    else
                    {
                        var clicked = false;
                        var path    = DownloadImage(imageurl);
                        var objects = Yolo.DetectObjects(path);
                        foreach (var _object in objects)
                        {
                            Console.WriteLine($"{_object.Confidence} -> {_object.Type}");
                            if (_object.Type == thing && !clicked)
                            {
                                Console.WriteLine("[!] CLICKED FROM YOLO [!]");
                                clicked = true;
                                await challenge.ClickAsync($"body > div.challenge-container > div > div > div.task-grid > div:nth-child({j}) > div.image-wrapper > div");
                            }
                        }
                        File.Delete(path);
                    }
                }
                Console.WriteLine("[!] DONE RECOGNISING [!]");
                await challenge.WaitForTimeoutAsync(2000);

                await challenge.ClickAsync("body > div.challenge-interface > div.button-submit");

                Console.WriteLine("[!] NEXT/SUBMIT [!]");
            }

            await page.WaitForTimeoutAsync(5000);

            await browser.CloseAsync();

            return(true);
        }
Esempio n. 12
0
            public static INewCEPExpression MakeExpr(string expr, out string compileErrors)
            {
                Yolo.Express();
                //string code = Resource1.template;
                string code = Resources.templateExpr.Replace(REPLACE_TOKEN, expr);
                //string code = File.ReadAllText(TEMPLATE_PATH).Replace(REPLACE_TOKEN, lambda);

                var provider = new CSharpCodeProvider(
                    new Dictionary <String, String> {
                    { "CompilerVersion", "v4.0" }
                });
                ICodeCompiler compiler = provider.CreateCompiler();

                var compilerparams = new CompilerParameters();

                compilerparams.GenerateExecutable = false;
                compilerparams.GenerateInMemory   = true;

                IEnumerable <string> referencedAssemblies = typeof(YoloWrapper).Assembly.GetReferencedAssemblies().Select(a => a.Name);

                foreach (string referencedAssembly in referencedAssemblies)
                {
                    string name = referencedAssembly + ".dll";
                    if (name != "WindowsBase.dll")
                    {
                        compilerparams.ReferencedAssemblies.Add(name);
                    }
                }

                //compilerparams.ReferencedAssemblies.Add(typeof(YoloWrapper).Assembly.GetName().Name + ".exe");

                foreach (string f in Directory.GetFiles(Environment.CurrentDirectory, "*.dll"))
                {
                    compilerparams.ReferencedAssemblies.Add(f);
                }

                CompilerResults results = RuntimeCodeCompiler.CompileCode(code);

                if (results.Errors.HasErrors)
                {
                    var errors = new StringBuilder("Compiler Errors :\r\n");
                    foreach (CompilerError error in results.Errors)
                    {
                        errors.AppendFormat("Line {0},{1}\t: {2}\n",
                                            error.Line, error.Column, error.ErrorText);
                    }
                    Console.Write("-");
                    compileErrors = errors.ToString();
                    throw new Exception(errors.ToString());
                }
                compileErrors = "";

                Assembly assm = results.CompiledAssembly;

                foreach (Type t in assm.DefinedTypes)
                {
                    object wrapper = Activator.CreateInstance(t);
                    return((INewCEPExpression)t.InvokeMember("Generate", BindingFlags.InvokeMethod, null, wrapper, null));
                }
                compileErrors = "";
                return(null);
            }