I tried moving the image to the specified folder by right-clicking and left-clicking

Introduction

I made it while thinking that I should be able to classify images easily.

What I made

I made a program to move images to a specified folder by right-clicking and left-clicking.

media.gif

The image was downloaded from the standard image database SIDBA of Kanagawa Institute of Technology. explorer.jpg

When you run the program, 5 images will be displayed. window.jpg

I clicked on the image of the earth. The window will be updated.

updated.jpg

The image of the clicked earth has been moved. Since it was a left click this time, it is output to the L folder.

updatedWindow.jpg

code

imageMover.py


import cv2
import glob
import shutil
import os
import numpy as np

#Image size is unified at 200px
size = (200, 200)  

name = []   #file name
data = []   #File data
coordinates = []    #Coordinates when clicked

#Create a destination folder. L and R correspond to left click and right click respectively.
os.makedirs('./L', exist_ok=True)
os.makedirs('./R', exist_ok=True)

#Read file
for file in glob.glob('*.bmp'):
    img = cv2.imread(file)
    img = cv2.resize(img, size) 
    name.append(file) 
    data.append(img)

#Function executed when mouse click
def click_event(event, x, y, flags, param):
    if event == cv2.EVENT_LBUTTONDOWN:
        coordinates[0:3] = [x, y, 'L']
    if event == cv2.EVENT_RBUTTONDOWN:
        coordinates[0:3] = [x, y, 'R']

#Number of images
hasWindow = len(data)

#Execute when the number of remaining images is 1 or more
while hasWindow > 0:
    img = cv2.hconcat(data[:5])

    while(1):
        cv2.imshow('img', img)
        cv2.setMouseCallback("img", click_event) #When clicked
        
        #Get the coordinates when clicked and move the corresponding image
        if len(coordinates) != 0:
            n = coordinates[0]//200
            shutil.move(name[n], coordinates[2]+'/'+name[n])
            print(F'folder{coordinates[2]}To{name[n]}Moved')
            data.pop(n)
            name.pop(n)
            coordinates = []
            hasWindow -= 1 #Update the remaining number of images
            break
        
        #Initialize coordinates
        coordinates = []    

        #Is there a key input
        key = cv2.waitKey(100) & 0xff

        #Close window when keyboard or x is pressed
        if key != 255 or cv2.getWindowProperty('img', cv2.WND_PROP_AUTOSIZE) == -1:
            cv2.destroyAllWindows()
            exit()

I have also uploaded it to Github.

Conclusion

Isn't manual faster?

in conclusion

It seems that you can devise more by increasing the number of images displayed.

Thank you for watching until the end. We look forward to your suggestions and comments.

Recommended Posts

I tried moving the image to the specified folder by right-clicking and left-clicking
I tried to get an image by scraping
I tried to correct the keystone of the image
I tried to verify and analyze the acceleration of Python by Cython
I tried to process and transform the image and expand the data for machine learning
I tried to pass the G test and E qualification by training from 50
I tried to detect the iris from the camera image
Resize the image to the specified size and blacken the margins
I tried to compress the image using machine learning
I tried to find the entropy of the image with python
I tried to illustrate the time and time in C language
I tried to display the time and today's weather w
I tried to enumerate the differences between java and python
I tried to verify the yin and yang classification of Hololive members by machine learning
I tried to move the ball
I tried to estimate the interval.
I tried to build the SD boot image of LicheePi Nano
I tried to visualize the Beverage Preference Dataset by tensor decomposition.
I tried to process the image in "sketch style" with OpenCV
I tried to summarize the commands used by beginner engineers today
I tried to predict by letting RNN learn the sine wave
I tried to process the image in "pencil style" with OpenCV
I tried to cut out a still image from the video
I tried to solve the shift scheduling problem by various methods
I tried to make an image classification BOT by combining TensorFlow Lite and LINE Messaging API
[RHEL7 / CentOS7] I put in the log monitoring tool swatch and tried to notify by email
I tried to summarize the umask command
I tried to recognize the wake word
I tried to summarize the graphical modeling.
I tried to estimate the pi stochastically
I tried to touch the COTOHA API
I tried playing with the image with Pillow
I tried to transform the face image using sparse_image_warp of TensorFlow Addons
I tried to summarize until I quit the bank and became an engineer
I tried to get the batting results of Hachinai using image processing
I tried to visualize the age group and rate distribution of Atcoder
I tried to summarize the general flow up to service creation by self-education.
I tried to express sadness and joy with the stable marriage problem.
765 I tried to identify the three professional families by CNN (with Chainer 2.0.0)
I tried to learn the angle from sin and cos with chainer
I tried to find the optimal path of the dreamland by (quantum) annealing
I tried to extract and illustrate the stage of the story using COTOHA
I tried to summarize the Linux commands used by beginner engineers today-Part 1-
I tried to classify Oba Hana and Emiri Otani by deep learning
I tried to solve the inverted pendulum problem (Cart Pole) by Q-learning.
I tried to verify the result of A / B test by chi-square test
I implemented the VGG16 model in Keras and tried to identify CIFAR10
I tried to analyze the New Year's card by myself using python
I tried to control the network bandwidth and delay with the tc command
I tried to open the latest data of the Excel file managed by date in the folder with Python
I tried to notify the update of "Hamelin" using "Beautiful Soup" and "IFTTT"
I tried "smoothing" the image with Python + OpenCV
[Python] I tried to judge the member image of the idol group using Keras
I tried "differentiating" the image with Python + OpenCV
I implemented DCGAN and tried to generate apples
I tried to optimize while drying the laundry
I tried to save the data with discord
I tried to touch the API of ebay
I tried "binarizing" the image with Python + OpenCV
I made an image classification model and tried to move it on mobile
I tried to predict the presence or absence of snow by machine learning.