简体   繁体   English

如何在C#中检测图像中的对象?

[英]How to detect objects in an image in c#?

I am building a C# project to detect all objects in the image , I don't want it to detect what is these objects , I just want it to detect the position of the objects in the image . 我正在建立一个C#项目来检测图像中的所有对象,我不希望它检测到这些对象是什么,我只是希望它检测对象在图像中的位置。

I have tried many ways to do it like this (using imageai python library then I used this script in c#) and this (using Alturos.Yolo library) tutorials, but these tutorials detect the known objects only but did not detect the position of an object if it do not know what is this object . 我已经尝试了许多方法来做到这一点 (使用imageai python库,然后在c#中使用此脚本)和 (使用Alturos.Yolo库)教程,但是这些教程仅检测已知对象,而未检测到对象的位置。对象,如果不知道这个对象是什么。

What I need is to detect the position of the object whether it recognize what is this object or not . 我需要的是检测对象的位置,无论它是否识别该对象。

For example in this image 例如在这张图片中

图片

it detects the only the objects it recognize their type but I want it to detect all the objects in the image. 它仅检测可识别其类型的对象,但我希望它检测图像中的所有对象。

python code : python代码:

detector = ObjectDetection()
detector.setModelTypeAsRetinaNet()
detector.setModelPath( os.path.join(execution_path , "resnet50_coco_best_v2.0.1.h5"))
detector.loadModel()
detections = 
detector.detectObjectsFromImage(input_image=os.path.join(execution_path , rel_path ,file_name), output_image_path=os.path.join(execution_path ,new_file_name))
for eachObject in detections:
    print(eachObject["name"] , " : " , eachObject["percentage_probability"] ," : "  ,eachObject["box_points"]  )

using Alturos.Yolo library code : 使用Alturos.Yolo库代码:

var configurationDetector = new ConfigurationDetector();
var config = configurationDetector.Detect();

using (var yoloWrapper = new YoloWrapper(config))
{
    using (MemoryStream ms = new MemoryStream())
    {
        pictureBox1.Image.Save(ms, ImageFormat.Png);
        var items = yoloWrapper.Detect(ms.ToArray());
        yoloItemBindingSource.DataSource = items;
        arr = items.ToArray();
    }
}

can anyone help or recommend another way please ? 任何人都可以帮忙或推荐其他方式吗?

Here is a similar question with some answers that may help you. 是一个类似的问题,其中的一些答案可能会对您有所帮助。 Here are a few options I have found: 这是我找到的一些选项:

AForge.Net AForge.Net

Some Methods: 一些方法:

* ColorFiltering
* ChannelFiltering
* HSLFiltering
* YCbCrFiltering
* EuclideanColorFiltering

OpenCV OpenCV的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM