For those who are currently building Computer Vision System for their Hangprinters. I made a DLC to Tobben's work on auto calibration simulation for Hangprinter.
Markers Positions Detector is an independent program which detects markers placed on the Hangprinter's effector (or on the "mover") and calculates distances between them.
Main goal of this detector is to automate and simplify process of obtaining markers positions.
As an output is XML file which is generated by program itself and it contains XYZ coordinates of each marker. This XML file is later used by
hpm program, but it's not necessary for using Markers Positions Detector.
It is assumed that you have python installed on your computer. If you don't, follow instructions below.
sudo apt update
sudo apt install python3
And check the version of your currently installed python.
python3 --version
If you succeed, you can move on. Clone this repository with:
git clone https://github.com/matusbalazi/BP-Markers-Positions-Detector
I recommend using PyCharm IDE, but also ordinary command line will work well.
You will also need to install the following packages:
opencv,
numpy,
scipy,
mystic,
pillow,
colorama.
If you have PyCharm IDE just hit Alt+Enter when your cursor is placed on the red underlined package and select Install package.
If you have only command line interface follow these commands:
sudo apt update
# install cv2 package
sudo apt install python3-opencv
# install numpy package
sudo apt install python3-pip
sudo pip install numpy
# install scipy package
sudo apt install python3-scipy
# install mystic package
sudo pip install mystic
# install PIL package
sudo pip install pillow
# install colorama package
sudo pip install colorama
To run Markers Positions Detector program type to Terminal following:
python ./main.py
or
python3 ./main.py
There is a bunch of arguments you can add to speed up later process:
- -i or --image means path to the input image
- -wi or --width means width of the output image
- -he or --height means height of the output image
- -c or --coords means comma separated list of source points to be transformed (write all this list in quotes)
python ./main.py --image input_images_examples/image3.jpg --width 1438 --height 1200 --coords "[(253,572),(870,214),(545,1073),(1162,715)]"
You will also need some photo of your markers placed on the effector. You can take a photo with any camera. I'm using same camera as Tobben (Arducam 8MP Sony IMX219 camera module with M2504ZH05 Arducam lens). I recommend to reduce shutter time while taking a photo to avoid unwanted noise in the image. But our algorithm should work well with any value of shutter. If you have some kind of PiCam and you have installed correct version of raspistill which matches your lens you can take a photo by typing:
raspistill --quality 100 --timeout 300 --shutter 100000 --ISO 50 --width 3280 --height 2464
Lower value of shutter makes brighter image, higher makes darker image.
The algorithm relies on the photo being taken from the location opposite to anchor B of Hangprinter to detect the markers in the correct order
so the user does not have to do anything. Otherwise if the photo is taken from another angle (from location opposite to anchor A or C)
you will have to rearrange calculated distances in the text file to correct order.
Markers should be detected in the order as shown in the image below.
Where the individual tag numbers stand for:
- 0 - nozzle
- 1-6 - markers numbered from 0 to 5
To detect nozzle position I pushed the pin to coupling on the extruder and screwed (or you can glue it) reflective disc to this pin.
In the stl folder of this repo you will
find stls of pins. They have different lengths and tolerances. Choose the one that suits you best.
Markers Positions Detector detects markers (probably you have reflective discs, but any circular shape will work) and calculates 21 distances between them in the following order:
- 0->1, 0->2, 0->3, 0->4, 0->5, 0->6,
- 1->2, 1->3, 1->4, 1->5, 1->6,
- 2->3, 2->4, 2->5, 2->6,
- 3->4, 3->5, 3->6,
- 4->5, 4->6,
- 5->6.
If you have everything ready, let's run the application.
I'll show you only some basic steps to use. The application gives you enough help while using it. This is only CLI application. In the main menu you will find 4 options to choose from:
- Perspective transformation
- Circle detector w/distance calculator (OpenCV)
- Circle detector w/distance calculator
- End detection and start analyzing data
- If the angle at which you took the photo is too large it is sometimes beneficial to transform the image to "bird's-eye view".
- Detects circles and calculates distances between them using OpenCV functions. This detection is fast but sometimes it isn't so reliable.
- Detects circles and calculates distances between them, but doesn't use OpenCV functions. This detection is slow but sometimes a little bit more reliable.
- After succesful detection analyzes measurements and generates XML file with XYZ coordinates of each marker on the effector.
Program asks if we want to analyze original or transformed image.
We need to enter the necessary parameters and choose the detection method. After that detection will start.
If no circles detected or the required number of circles was not detected we can run advanced circle detection.
All circles were detected, distances between them were calculated and written to text file, output image was saved. Check the order of detected circles. It must match the correct order as was shown in the Preparations part. Output image is little bit messy but later take a look in the text file result.txt. There are written calculated distances. To continue hit the Enter to close the image.
Now we can start to analyze data that we got to achieve markers positions.
Here begins Tobben's script which I edited. We got best intermediate cost and positions of our markers, but truly important for us is to get best final cost and positions. To get that we have to manually measure Z height (in milimeters), which is distance between nozzle plane and markers plane.
Finally we got what we wanted all the time. XYZ positions of markers on the effector. Value of best final cost should be less than 3 so that we can consider the results are reliable.
This is how the generated XML file with marker parameters looks like. This file is important if we want to use hpm program.
That was a quick look at Markers Positions Detector program. I hope it will help you. You can try another detection methods.
They work very similarly. Also look at input_images_examples
and output_images folders. There are decent
examples of input and output images.
If anyone is interested in UML Class Diagrams so here it is. See the comments in code for more detailed descriptions of the funtions.