[PYTHON] I tried to sort out the objects from the image of the steak set meal-① Object detection

Introduction

Previously, I performed object detection using OpenCV, but how much difference is there in accuracy because there is a library named Selective Search? I tried to compare.

Also, previously I tried another method after reviewing the environment construction that I didn't understand very much. So it's a little different.

In addition, when I tried it, Selective Search does not work properly because the function is different in Python3.

Selective Search

Selective Search

Plagiarism

I tried using Selective search as R-CNN

environment

# OS/software/Library version
1 Mac OS X EI Capitan
2 Python 2.7 series
3 OpenCV 3.2 system
4 Selective Search
5 matplotlib 2.0 series

Build

With previous

Updated to latest

brew update

tap

brew tap homebrew/python
brew tap homebrew/science

Python installation

brew install python

Check the path

which python
/usr/local/bin/python ※1

PATH setting

.zshrc


if [ -d $(brew --prefix)/lib/python2.7/site-packages ];then
  export PYTHONPATH=$(brew --prefix)/lib/python2.7/site-packages:$PYTHONPAT
fi

Check version

python
Python 2.7.13 (default, Apr  4 2017, 08:46:44) 
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

Different from here

Put a link in Applications

brew linkapps

install pip

easy_install pip

Update setuptools to the latest version

pip install --upgrade setuptools

Update pip to the latest version

pip install --upgrade pip

Install OpenCV3

pip install opencv-python

Install NumPy

pip install numpy

Install MatplotLib

pip install matplotlib

Install Selective Search

pip install selectivesearch

Comparison

image

This time I will use this steak set meal. Use Previous as the source code for comparing object detection.

steak.jpg

Selective Search source code

I tried using Selective search as R-CNN is used as it is.

grouping_image.py


import cv2
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
import selectivesearch

def main():
        # loading lena image
    img = cv2.imread("{Image path}")

    # perform selective search
    img_lbl, regions = selectivesearch.selective_search(
        img, scale=500, sigma=0.9, min_size=10)

    candidates = set()
    for r in regions:
        # excluding same rectangle (with different segments)
        if r['rect'] in candidates:
            continue
        # excluding regions smaller than 2000 pixels
        if r['size'] < 2000:
            continue
        # distorted rects
        x, y, w, h = r['rect']
        if w / h > 1.2 or h / w > 1.2:
            continue
        candidates.add(r['rect'])

    # draw rectangles on the original image
    fig, ax = plt.subplots(ncols=1, nrows=1, figsize=(6, 6))
    ax.imshow(img)
    for x, y, w, h in candidates:
        print(x, y, w, h)
        rect = mpatches.Rectangle(
            (x, y), w, h, fill=False, edgecolor='red', linewidth=1)
        ax.add_patch(rect)

        cv2.imwrite('{Directory path}' + str(x) + '.jpg', img[y:y + h, x:x + w])

    plt.show()

if __name__ == "__main__":
    main()

result

Compare how many dishes, foods and seasonings can be contoured. As for the level, I'm strict about it because it can be extracted for one bowl or plate.

Normal case

Two

56.jpg

223.jpg

For Selective Search

5

57.jpg

227.jpg

379.jpg

405.jpg

273.jpg

Impressions

--Selective Search was more accurate. ――Even in Selective Search, the meat was not detected cleanly even though it was a steak set meal.

329.jpg

238.jpg

――Is it doing various processing? Selective Search took some speed (about 10 seconds?). ――The functions are quite different depending on the version of Python or OpenCV, which is troublesome. ――I don't feel like I can write Python or OpenCV from scratch in spite of doing various things.

All page links

-I tried object detection using Python and OpenCV -I tried to sort out objects from the image of steak set meal-① Object detection -I tried to sort out the objects from the image of the steak set meal-② Overlap number sorting -I tried to sort out the objects from the image of the steak set meal-③ Similar image heat map detection -I tried to sort out the objects from the image of the steak set meal-④ Clustering -I tried to sort out objects from the image of steak set meal-⑤ Similar image feature point detection edition

Recommended Posts

I tried to sort out the objects from the image of the steak set meal-① Object detection
I tried to sort out the objects from the image of the steak set meal-④ Clustering
I tried to sort out the objects from the image of the steak set meal --③ Similar image Heat map detection
I tried to sort out the objects from the image of the steak set meal-⑤ Similar image feature point detection
I tried to sort out the objects from the image of the steak set meal-② Overlap number sorting
I tried to cut out a still image from the video
I tried to correct the keystone of the image
I tried to detect the iris from the camera image
I tried to find the entropy of the image with python
I tried to build the SD boot image of LicheePi Nano
I tried to transform the face image using sparse_image_warp of TensorFlow Addons
I tried to get the batting results of Hachinai using image processing
I tried to summarize the logical way of thinking about object orientation.
I tried to touch the API of ebay
I tried using the image filter of OpenCV
I tried to predict the price of ETF
I tried to vectorize the lyrics of Hinatazaka46!
[Python] I tried to judge the member image of the idol group using Keras
I tried object detection with YOLO v3 (TensorFlow 2.1) on the GPU of windows!
I tried to automate the face hiding work of the coordination image for wear
I tried to predict the number of people infected with coronavirus in consideration of the effect of refraining from going out
I tried to summarize the basic form of GPLVM
I tried to visualize the spacha information of VTuber
I tried to erase the negative part of Meros
I tried to classify the voices of voice actors
I tried to compress the image using machine learning
I tried to summarize the string operations of Python
I tried to put out the frequent word ranking of LINE talk with Python
I tried to extract the text in the image file using Tesseract of the OCR engine
[Horse Racing] I tried to quantify the strength of racehorses
I tried "gamma correction" of the image with Python + OpenCV
I tried to get the location information of Odakyu Bus
I tried to find the average of the sequence with TensorFlow
[Python] I tried to visualize the follow relationship of Twitter
[Machine learning] I tried to summarize the theory of Adaboost
I tried to predict the genre of music from the song title on the Recurrent Neural Network
I tried to fight the Local Minimum of Goldstein-Price Function
I want to cut out only the face from a person image with Python and save it ~ Face detection and trimming with face_recognition ~
I tried changing the python script from 2.7.11 to 3.6.0 on windows10
I tried to get various information from the codeforces API
Implementation of recommendation system ~ I tried to find the similarity from the outline of the movie using TF-IDF ~
I tried using PI Fu to generate a 3D model of a person from one image
I tried to find the trend of the number of ships in Tokyo Bay from satellite images.
[For beginners] I tried using the Tensorflow Object Detection API
[Linux] I tried to summarize the command of resource confirmation system
I tried to get the index of the list using the enumerate function
I tried to automate the watering of the planter with Raspberry Pi
[Python] Try to graph from the image of Ring Fit [OCR]
I tried to process the image in "sketch style" with OpenCV
I tried to process the image in "pencil style" with OpenCV
I tried to expand the size of the logical volume with LVM
I tried to summarize the frequently used implementation method of pytest-mock
I tried to improve the efficiency of daily work with Python
I tried to visualize the common condition of VTuber channel viewers
I tried to move the ball
I tried to estimate the interval.
[Python] I tried to reproduce the emergency escape program to return from the world to return from the modified world of "The disappearance of Haruhi Suzumiya"
I tried to make a thumbnail image of the best avoidance flag-chan! With RGB values ​​[Histogram] [Visualization]
I tried to deliver mail from Node.js and Python using the mail delivery service (SendGrid) of IBM Cloud!
[Python] I tried to summarize the set type (set) in an easy-to-understand manner.
I tried moving the image to the specified folder by right-clicking and left-clicking