Detects and counts Object in Images. Running Python3 and OpenCV on Jupyter Nodebook
This is no Yolo or object models based solution.
Im using matchTemplate from Open-CV on static images.
- sometime you have to count hundrets of objects like in PDF CAD Files where you dont have access to the original files from the architect.
- You need y,x Coordinates of Objects in an Image
- detect Objects in Images
- Count the objects
- Draw a rectangle and number on the object and save the image
- export the x,y coordinates to json, csv and text
- mass import for as many "haystack" images as you like
- Cross platform [Win,Linux] (no Idea about Mac)
- Windows executable
- Data
\ stacks - Insert the "haystack" Images here
\ needle - The "Needle" we want to find in the Haystack
\ output - Storage Folder for the processed Images
\ output_csv - Log Folder for txt,json and csv files
- Prepare your Haystack Image. Transparent Images are not working. Put it in the stacks Folder.
- Some Autocad Export PDFs are transparent. Add a white Background.
- Create a needle Image what you are looking for. The needle Image must have to same size as the objects you are looking for in the image. Copy it in the Needle Folder and rename it to needle_4k.png
Should look like this for the expample shown here:
Haystack Images should be larger then the needle Images. I used around 4k resolution. Put as many images as you like in the stacks Folder. Importand is, that the needle Image has to be in the same size because the script don't resize the needle.
Look at the demo Image for an example.
If something goes wrong, set __DEBUG = True
- Download latest Release Version from https://github.com/corgan2222/E-Shelter_ObjectCount/releases/
- Extract Zip File
- Start exe
git clone https://github.com/corgan2222/E-Shelter_ObjectCount.git
cd E-Shelter_ObjectCount/objectcounter
./install_linux.sh
python3 -m pip install -r requirements.txt
- Install WSL2 (Windows Subsystem for Linux)
- Install a Linux Distro like Ubuntu
- Login via SSH to your local WSL Instance
git clone https://github.com/corgan2222/E-Shelter_ObjectCount.git
cd E-Shelter_ObjectCount
chmod +x install.sh
./install_jupyter.sh
then open the Jupyter URL in the Browser. Typically http://localhost:8888/lab?
There are two running modes.
python3 objectcounter.py
- just run the script with no parameter.
- The script will look in the data/stacks and data/needle Folder for Files.
- If the Output Folder not exists in the data Folder they got created
You can define all files and Folder via command line parameter
python3 objectcounter.py -i [image] -t [templatefile]
example Windows
python3 objectcounter.py -i "c:\tmp\image.png" -t "c:\tmp\needle.png"
example Linux
python3 objectcounter.py -i "/home/user/files/image.png" -t "/home/user/files/needle.png"
Option | Description | Notes |
---|---|---|
-i | Imagefile | "/home/user/files/image.png" |
-t | Templatefile | "/home/user/files/needle.png" |
-o | Output Folder | "/home/user/files/data/output" |
-c | CSV&Txt Folder | "/home/user/files/data/output_csv" |
-s | Stacks Folder | "/home/user/files/data/stacks" |
-T | Tolerance | float 0-1 default 0.6 |
-l | Logfile | "/car/log/debug.log" |
-v | verbose | show debug logs if set |
-q | quit | no output |
- Testing, this is a alpha release
- add Screenshot Tool to create needle Images faster
- add flask Webserver
- Create Docker File
- make a standalone version for Windows user
- Jupyter
- OpenCV
- https://github.com/ClarityCoders
- https://github.com/starcraft04/swauto ! Most of the code to prevent OpenCV from double counting. Thanks a lot!