Build Your Own AI Assistant Part 1 - Creating the Assistant
116316 Views
Is the new Raspberry Pi AI Kit better than Google Coral?
111570 Views
Control Arduino with Python using Firmata / PyFirmata
86865 Views
How to Map with LiDAR - using a Raspberry Pi Zero 2W, RPLidar and Rviz
56603 Views
Creating a Supercomputer with a Raspberry Pi 5 Cluster and Docker Swarm!
52712 Views
Node-Red Automation, MQTT, NodeMCU & MicroPython
51798 Views
Weather Station Display
Pi 10 Inch Mini-rack
Installing and Using DeepSeek-R1:1.5 on a Raspberry Pi with Docker
Gamepad & BurgerBot
Level Up your CAD Skills
Operation Pico
Mini-Rack 3D Design Tutorial
0h 20m
Using the Raspberry Pi Pico's Built-in Temperature Sensor
0h 24m
Getting Started with SQL
0h 32m
Introduction to the Linux Command Line on Raspberry Pi OS
0h 42m
How to install MicroPython
0h 8m
Wall Drawing Robot Tutorial
0h 22m
Learn Linux from the basics to advanced topics.
Learn how to use a Raspberry Pi Pico
Learn MicroPython the best language for MicroControllers
Learn Docker, the leading containerization platform. Docker is used to build, ship, and run applications in a consistent and reliable manner, making it a popular choice for DevOps and cloud-native development.
Learn how to build SMARS robots, starting with the 3D Printing the model, Designing SMARS and Programming SMARS
Learn how to build robots, starting with the basics, then move on to learning Python and MicroPython for microcontrollers, finally learn how to make things with Fusion 360.
Learn Python, the most popular programming language in the world. Python is used in many different areas, including Web Development, Data Science, Machine Learning, Robotics and more.
Learn how to create robots in 3D, using Fusion 360 and FreeCAD. The models can be printed out using a 3d printer and then assembled into a physical robot.
Learn how to create Databases in Python, with SQLite3 and Redis.
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 >