A simple interactive drawing application built with Python and OpenCV that allows users to create drawings and shapes with different colors and thicknesses.
- Multiple drawing modes:
- Freehand drawing
- Circle drawing
- Rectangle drawing
- Line drawing
- Color options (Red, Green, Blue)
- Adjustable line thickness
- Save functionality
- Python 3.x
- OpenCV (
cv2
) - NumPy
To install the required packages:
pip install opencv-python numpy
- Run the script:
python canvas.py
- The application will open with a white canvas window.
-
Mouse Controls:
- Left Click + Hold: Draw/Create shapes
- Release Left Click: Complete shape drawing
-
Keyboard Controls:
m
: Switch between drawing modes (freehand/circle/rectangle/line)c
: Change colors (Red/Green/Blue)+
: Increase line thickness-
: Decrease line thicknesss
: Save drawing as "MyImage.png"q
: Quit application
-
Freehand Mode
- Click and drag to draw freely
-
Circle Mode
- Click for center point
- Drag to set radius
- Release to complete
-
Rectangle Mode
- Click for first corner
- Drag to opposite corner
- Release to complete
-
Line Mode
- Click for start point
- Drag to end point
- Release to complete
When saving, the drawing will be stored as "MyImage.png" in the same directory as the script.
- Canvas Size: 800x600 pixels
- Default Color: Red (BGR format: 0,0,255)
- Default Thickness: 2
- Image Format: PNG (when saving)
- The thickness cannot be reduced below 1
- The application can be safely closed using 'q' key or the window close button
Potential features for future versions:
- Additional shape options
- More color choices
- Undo/Redo functionality
- Layer support
- Custom canvas sizes