106994 Views
83035 Views
47973 Views
47955 Views
47413 Views
46546 Views
Two-Way Bluetooth Communication Between Raspberry Pi Picos
Gamepad 2
Picotamachibi 2
Learning System updates
BrachioGraph
HP Robots Otto
Introduction to the Linux Command Line on Raspberry Pi OS
How to install MicroPython
Wall Drawing Robot Tutorial
BrachioGraph Tutorial
Intermediate level MicroPython
Introduction to FreeCAD for Beginners
KevsRobots Learning Platform
84% Percent Complete
By Kevin McAleer, 3 Minutes
The linedraw.py module allows you to convert bitmap images into vector format. This can be useful for creating images that your BrachioGraph can draw. The module helps you convert a bitmap image file into an SVG file for visual verification and a JSON file for use with the BrachioGraph.
linedraw.py
First, you’ll need to install the opencv-python-headless package, as it is not included in the standard requirements.txt. You can install it using the following command:
opencv-python-headless
requirements.txt
pip install opencv-python-headless
Launch a Python shell and import the necessary functions from linedraw:
linedraw
from linedraw import *
image_to_json()
To convert an image to a JSON file, you can use the image_to_json function. For instance, to convert an image named africa.jpg located in the images directory, you can use the following command:
image_to_json
africa.jpg
images
image_to_json("images/africa", draw_contours=2, draw_hatch=16)
This command performs the following tasks:
africa
africa.png
africa.tif
africa.json
africa.jpg.json
africa.svg
africa.jpg.svg
A draw_contours or draw_hatch value of 0 will disable those features. Lower values provide more detail, while higher values provide less. Experiment with these values to find the best settings:
draw_contours
draw_hatch
You can emphasize the edges of your image by using the repeat_contours parameter. For example:
repeat_contours
image_to_json("images/africa", draw_contours=2, draw_hatch=16, repeat_contours=3)
Setting repeat_contours=3 means that the contour data will be added to the JSON file three times, making the edges stand out more prominently. This is particularly effective with pencil drawings.
repeat_contours=3
To verify the results, open the generated SVG file. You can draw the JSON file with the BrachioGraph using the following command:
BrachioGraph.plot_file("images/africa.json")
vectorise()
If you want to get the lines in a format that you can process in a shell or script, use the vectorise function:
vectorise
lines = vectorise("images/africa.jpg", draw_hatch=16, draw_contours=2)
This command generates:
Refer to the vectorise function documentation for full details on the parameters it accepts.
draw()
The draw function allows you to visualize how the plotter will draw the lines using Python’s turtle graphics module:
draw
draw(lines)
This function sequentially draws the lines generated by vectorise(). Although it is slower than the actual plotter, it provides a useful preview of the drawing process.
With these tools and techniques, you can effectively convert and optimize images for your BrachioGraph, ensuring that your drawings are accurate and detailed.
< Previous Next >