简体   繁体   English

OpenCV多图像检测

[英]OpenCV Multiple Image Detection

i'm trying to build a simple image detection algorithm in which will classify different objects such as plastic cups, bottles, cell phones, etc. What is the best way to implement this using openCV and python? 我正在尝试构建一种简单的图像检测算法,该算法将对不同的对象进行分类,例如塑料杯,瓶子,手机等。使用openCV和python实现此目的的最佳方法是什么? Thanks 谢谢

If you are looking for a algorithm or model that can detect various objects ie classify given image you have to look in to Conv Nets (CNN). 如果您正在寻找可检测各种物体(即对给定图像进行分类)的算法或模型,则必须查看Conv Nets(CNN)。

A CNN is a deep learning model that can be trained on the classes of images you want to detect. CNN是一种深度学习模型,可以在要检测的图像类别上进行训练。 Later different images can be provided to the trained CNN to get the predictions. 之后,可以将不同的图像提供给受过训练的CNN以获取预测。

If you are interested in this stuff, I recommend you to take a look in to this blog post. 如果您对此内容感兴趣,建议您阅读博客文章。

You can try to do some pattern matching for the images but the accuracy will drastically reduce if there is heavy variations. 您可以尝试对图像进行一些模式匹配,但是如果变化很大,则准确性会大大降低。

As far as I know you cannot train/build your own network on OpenCV. 据我所知,您无法在OpenCV上训练/构建自己的网络。 You could rather use OpenCV to load pre-trained models and perform detection on a set of images. 您宁愿使用OpenCV来加载预训练的模型并在一组图像上执行检测。

In order to create a new model you can use either caffe, torch or tensorflow frameworks and use it to perform detection in OpenCV. 为了创建一个新模型,您可以使用caffe,torch或tensorflow框架,并使用它在OpenCV中执行检测。

In order to perform detection you need to do the following: 为了执行检测,您需要执行以下操作:

  • First, ensure you have compiled OpenCV with the contrib module. 首先,请确保已使用contrib模块编译了OpenCV。 If you don't simply enter the following onyour terminal: pip install opencv-contrib-python . 如果您不只是在您的终端上输入以下内容: pip install opencv-contrib-python
  • First ensure you have cv2.dnn . 首先确保您拥有cv2.dnn If you don't you will need to update the version of OpenCV. 如果您不这样做,则需要更新OpenCV的版本。
  • Now you have an option to choose models from one of the following frameworks caffe, tensorflow, darkNet and torch: 现在您可以从以下框架之一中选择模型:caffe,tensorflow,darkNet和Torch:
    • readNetFromCaffe
    • readNetFromDarknet
    • readNetFromTensorflow
    • readNetFromTorch
  • After choosing a framework select a pre-trained model. 选择框架后,选择一个预先训练的模型。 You can get pre-trained caffe models from HERE and tensorflow models from HERE . 你可以从预先训练朱古力模型这里和tensorflow车型从这里 A good search on github will give you many more models. 在github上进行良好的搜索将为您提供更多模型。

I came across the dnn module after reading this blogpost by Adrian . 在阅读了Adrian的博客文章之后,我遇到了dnn模块。

Just to re-iterate you can perform detection using pre-trained models on OpenCV but not create new models. 只是重申一下,您可以使用OpenCV上的预训练模型执行检测,但不能创建新模型。

How do you run a pre-trained model? 您如何运行预训练模型?

  1. caffe : model= cv2.dnn.readNetFromCaffe(ResNet.prototxt.txt, ResNet.caffemodel) , where the prototxt.txt file contains the architecture and the other file contains the model weights. caffemodel= cv2.dnn.readNetFromCaffe(ResNet.prototxt.txt, ResNet.caffemodel) ,其中prototxt.txt文件包含架构,另一个文件包含模型权重。

  2. tensorflow : model = cv2.dnn.readNetFromCaffe(ResNet.pb, ResNet.pbtxt) , where .pb file containns the netwrok architecture and .pbtxt contains the model weights. tensorflowmodel = cv2.dnn.readNetFromCaffe(ResNet.pb, ResNet.pbtxt) ,其中.pb文件包含.pbtxt体系结构, .pbtxt包含模型权重。

Refer to the link for more details. 请参阅链接以获取更多详细信息。

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

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