/ImageCap

A Python Software for rapid image capture for neural network training. Support ratio-protected image resize and image rotate.

Primary LanguagePythonGNU General Public License v3.0GPL-3.0

ImageCap

Select Language: English | 简体中文



ImageCap is a Python Software for rapid image capture for neural network training. Support ratio-protected image resize and image rotate. GUI designed and generated by PySide2 (PyQt5).

Mainpage_of_ImageCap

Package Requirements

# Use pip to install following packages
pip install opencv-python
pip install pyside2
pip install qimage2ndarray

# import
import cv2
import sys
from PySide2 import QtCore, QtGui, QtWidgets
import qimage2ndarray

from PySide2.QtWidgets import QApplication, QMainWindow, QFileDialog, QMessageBox
from PySide2.QtGui import QImage, QPixmap
from PySide2.QtCore import QRect
from imagecap_ui import Ui_MainWindow

How To Use ImageCap to Take Photos

  • Use Width and Height input box to adjust the size(resolution, px) of the capture image. P.S. Preview Box DO NOT support Auto-Resize currently, so use resolution other than 416*416 might cause GUI bugs, pending to be solved in the next update version...
  • Use .png format to capture images by default.
  • Use index input box to input the index of the image. e.g. Input "0", the first capture image filename will be 1.png
  • Click Save Pref Button to save the configs above.

  • Before using Cap! to get a photo, user needs to select a saving path by clicking the Select Path Button below the Application Window. Otherwise an Error Box would pop up and remind the user that "Please select a saving directory first"
  • After selecting the saving path, you can click Cap! to take photos. The Status part of the application will also remind user of the saving status of the photos.
  • If the capture process is unexpectedly interrupted, you can reset the index with Index to continue taking and storing photos in the same path.

  • If the camera is mounted in the opposite direction (as in the case of some industrial cameras), then the Video Flip Check Box in the interface can be ticked to get a positive image.

Use ImageCap to Rotate Images Randomly

To train a neural network, it is often necessary to take photos of the target at different angles, so this function can be used to rotate the photos randomly without cropping. The results of this feature are as follows.

randomRotateResult

This function page is illustrated on the Picture below. Simply select the path where the original image is stored, select the path where the rotation results will be saved and click the Rotate button to start a random rotation, the live rotation results can be seen in the window in real time. Support rotation angle customization now. Simply input the degree you want in the degree input box and press "Save". Then "Rotate". Use any degree value > 0 to rotate anti-clockwise, and use any degree value < 0 e.g. (-30) to rotate clockwise.

randomRotateWindow

Example of rotating an image using a fixed angle:

randomRotateWindow_FIXED

Fit Background Using ImageCap

The images of the targets collected on the production line are always cropped and need to be scaled down to 416 * 416 images. This would be very cumbersome if PhotoShop was used to process them one by one. This function calculates the scale of the original target image and automatically calculates the pixel value of the width if it is scaled equally to a height of 416px. After scaling, the target image is moved to the background image to achieve the effect shown below.

fitBackgroundResult

The function page is shown below. Simply select the path where the target image is stored, select a solid colour or any background image to be used and select the image output path to start automatically applying the target to the background image to scale.

fitBackgroundWindow

Currently, you need to create your own background image in MS Paint with a size of 416 * 416 (currently it must be 416 * 416) and then select this image in the program. Or just use the QColorDialog to select a background color by clicking the select button of the Background Color section, then the programme will automatically generated a 416*416 background image with the color you've chosen.

selectColorFitBG

If you choose to use the generated background image, you do NOT need to select a background image again, the programme will automatically set the background image path to the generated background image.

The ability to customise the size of the background is not yet developed and will be released in the next version of ImageCap.


Other Files in the Project Folder

  • QtUI\imagecap.ui: A UI design file made by Qt Designer of PySide2, you can open it with Qt Designer and adjust the design.

  • imagecap_ui.py : A .py file that includes UI Design generated by the pyside2-uic command line tool. Use to load UI interfaces in ImageCap_GUI.py and gui_test_no_real_time.py

  • ui_fitBackground.py : A .py file automatically generated using PySide2's command line tools for loading the UI interface with the fit background function page in ImageCap_GUI.py.

  • ui_randomRotate.py : A .py file automatically generated using PySide2's command line tools for loading the UI interface for the random rotate function page in ImageCap_GUI.py.

  • ImageRotate.py : The function file used to randomly rotate the image