Insect detection using openCV

Hello, I am trying to make an AI to identify insects using openCV.

My scenario will be something like a glue trap for insects, and I have to detect and count the species in that trap (more importantly the fruitfly)

This is an example of an image i would have to detect:
Screenshot_16

I am a beginner with openCV, so i was wondering what would be the best aproach for this problem, Hog + SVM was one of the aproaches i could find online, but I would like more opinions on this.

If you need any more information feel free to ask,
Thank you!

please tell, what we should see in your image
(are there two kinds of insects ?)
and what you are trying to achieve with it

HOG descriptors are not rotation invariant (they also know a single “class” only), you probably cannot use them here

also, 40% of the image are covered by the fingers, just saying

so, for any kind of ml, you would need a few hundred annotated positive images. can you get that kind of data ?

In my image we should be able to identify and count how many fruit flies(the small orange ones) are in the trap. I only care about the fruit flies, maybe its also good to be able to identify others for comparision but i mostly need to identify the fruit fly.

Sorry for the fingers this was just an example, it should usually be only the trap, but i cant really find a good example.

Yes, from what i have seen, HOG might have trouble with this kind of data… i have seen YOLO and CNN working better but i am not sure if i can use them with only openCV.

About the “single class” i have seen an example where people use one class for more than one species to make it up for the lack of images in the dataset, but this is just stuff i researched, i dont have experience.

Yes, getting the images will maybe be a problem, its a one person job and i havent really found any datasets online about this. that is also why its hard for me to test which algorithm would work, i would need to know from experience

thank you for your answer

there are tools for annotation. cvat is one.

tapping/clicking on every fruit fly in a few hundred pictures should be a few hours of work maybe.

OpenCV has a dnn module. it is quite flexible. docs.opencv.org has tutorials and examples.

Start with the standard image processing steps.

  1. Extract the yellow patch by detecting a rectangle. https://www.pyimagesearch.com/2016/02/08/opencv-shape-detection/
  2. Transform the rectangle by rotation and translation and resize to a fixed size.
    https://www.pyimagesearch.com/2014/08/25/4-point-opencv-getperspective-transform-example/
  3. Do blob detection to get individual flies.

This pipeline will be necessary for both training and inference.

Try classical computer-vision methods starting with simple methods like blob size and color. Advance with feature-descriptor methods as mentioned (ORB HOG etc.)
If not sufficient, you will have the dubiously fun (yikes!) job of labelling a dataset.
For a CNN architecture, try reading up and implementing a Siamese-Network.

Look out for those bugs :mosquito: :mosquito: :ant:

2 Likes

Yes, i have nightmares about having to label the dataset :smiley:

Thank you for your answer!

1 Like