Draw a Forest of Random Tree Objects with Python OpenCV - Classes and OOP Practice for Beginners

Python Simplified September 6, 2021
Video Thumbnail
Python Simplified Logo

Python Simplified

@pythonsimplified

About

Hi everyone! My name is Mariya and I'm a software developer from Sofia, Bulgaria. I film programming tutorials about Computer Science Concepts, GUI Applications, Machine Learning and Artificial Intelligence, Automation and Web Scraping, Data Science and even Math! 🤓 I'm here to help you with your programming journey (in particular - your Python programming journey 😉) and show you how many beautiful and powerful things we can do with code! 💪💪💪

Video Description

In this tutorial, we will practice the principles of Object-Oriented Programming and draw a forest of unique tree objects. We will first create a Tree class and then we will replicate it in different locations, sizes and colours. We will also include a very large degree of randomness in our code, so that each time our program runs - a brand new forest with brand new trees is created! 🤩🤩🤩 🛑🤚 HAVE YOU WATCHED ✋🛑 ******************************************* 1. My OOP and Classes Tutorial: https://youtu.be/f0TrMH9s-VE 2. My Draw Shapes with OpenCV Tutorial: https://youtu.be/PtvN8ad9N3g ******************************************* ⏰ TIMESTAMPS ⏰ 00:00 - intro 00:16 - starter code overview 01:01 - create a class 01:22 - class attributes 02:07 - class methods 03:40 - call class 05:40 - relative coordinates 06:22 - draw object 09:04 - scale object 13:35 - fancy design tricks 14:40 - draw step repeat objects 16:04 - draw objects at random location 19:47 - draw with random colors 24:14 - coming soon and thank you! 🐍 STARTER CODE 🐍 ************************************************ import numpy as np import cv2 as cv import random # general parameters width = 900 height = 600 n_trees = 30 ground_level = height-100 # colours green, light_green, brown = (40,185,40),(25,220,0),(30,65,155) # blank image bg = np.zeros((height, width, 3), dtype=np.uint8) # draw background cv.rectangle(bg,(width,0), (0, ground_level), (255,225,95), -1) cv.rectangle(bg,(width, ground_level), (0, height), green, -1) # *************** # YOUR CODE GOES HERE # *************** #display image cv.imshow('forest of objects', bg) cv.waitKey(0) cv.destroyAllWindows() ************************************************ 🐍 END OF STARTER CODE 🐍 Didn't feel like coding along? 🙃 Get the complete code from my Github: https://github.com/MariyaSha/OpenCV_DrawImages/blob/main/completeCode_OpenCVForest.ipynb Thanks for watching! Find me on: LinkedIn - https://linkedin.com/in/mariyasha888/ Discord - https://discord.gg/WeTz5A2FfS

You May Also Like

Boost Your Python Graphics Skills Today

AI-recommended products based on this video

Loading...
4 Pack LCD Writing Tablet for Kids, 8.5 Inch Colorful Doodle Board Drawing Tablet, Educational Learning Toys Birthday Gifts for Boys Girls Age 3 4 5 6 7 8

4 Pack LCD Writing Tablet for Kids, 8.5 Inch Colorful Doodle Board Drawing Tablet, Educational Learning Toys Birthday Gifts for Boys Girls Age 3 4 5 6 7 8

(910)
$13.28
FREE delivery Sat, Jun 14 on your first order
500+ bought in past month
Loading...
Toys for Girls Boys, Colorful Doodle Board Drawing Tablet, Memo Board, Drawing Pads with Lanyard, Travel Educational Toys Gifts for Boys Girls Age 3 4 5 6 7 8 9 Years (Pink)
Best Seller

Toys for Girls Boys, Colorful Doodle Board Drawing Tablet, Memo Board, Drawing Pads with Lanyard, Travel Educational Toys Gifts for Boys Girls Age 3 4 5 6 7 8 9 Years (Pink)

(5,477)
$22.99
FREE delivery Sat, Jun 14 on your first order
1K+ bought in past month
Loading...
Toys for Girls 10 inch Doodle Board Drawing Pad Tablet with Lock Function, Erasable, Portable, Educational Learning Unicorn Toy Gifts for 3 4 5 6 7 8 9 Years Old Girls Toddlers (Pink)

Toys for Girls 10 inch Doodle Board Drawing Pad Tablet with Lock Function, Erasable, Portable, Educational Learning Unicorn Toy Gifts for 3 4 5 6 7 8 9 Years Old Girls Toddlers (Pink)

(4,341)
$21.99
FREE delivery Sat, Jun 14 on your first order
400+ bought in past month
Loading...
LCD Writing Tablet, Portable Erasable 6.5 Inch Full Screen Digital Notepad, Reuseable Electronic Drawing Pads, for Taking Notes, Drawing, Office, Study, Teaching

LCD Writing Tablet, Portable Erasable 6.5 Inch Full Screen Digital Notepad, Reuseable Electronic Drawing Pads, for Taking Notes, Drawing, Office, Study, Teaching

(3)
$15.69
FREE delivery Aug 19 - 29
Loading...
Acer Nitro V 16 AI Gaming Laptop, 16" WUXGA 180Hz Display, AMD Ryzen 5 240, GeForce RTX 5050, 16GB DDR5, 512GB SSD, Backlit Keyboard, Copilot, Wi-Fi 6E, Win 11, Black, 1TB Docking Station Set

Acer Nitro V 16 AI Gaming Laptop, 16" WUXGA 180Hz Display, AMD Ryzen 5 240, GeForce RTX 5050, 16GB DDR5, 512GB SSD, Backlit Keyboard, Copilot, Wi-Fi 6E, Win 11, Black, 1TB Docking Station Set

(40)
$1,399.00
FREE delivery Feb 24 - Mar 5
Loading...
Acer Nitro V 15.6" FHD 165Hz Gaming Laptop, Intel i5-13420H, 16GB RAM, 512GB SSD, NVIDIA GeForce RTX 5050 8GB GDDR7, Copilot, Backlit Keyboard, Wi-Fi 6, Win 11, Black, 1TB Docking Station Set

Acer Nitro V 15.6" FHD 165Hz Gaming Laptop, Intel i5-13420H, 16GB RAM, 512GB SSD, NVIDIA GeForce RTX 5050 8GB GDDR7, Copilot, Backlit Keyboard, Wi-Fi 6, Win 11, Black, 1TB Docking Station Set

(1,689)
$1,349.00
FREE delivery Feb 24 - Mar 5Only 7 left in stock.
Loading...
Acer Nitro V 15.6 FHD 144Hz Gaming Laptop, Intel i7-13620H, 32GB DDR5, 1TB SSD, NVIDIA GeForce RTX 4060, Keyboard Backlight, Wi-Fi 6, HD Webcam, Windows 11 Home, Black, 256GB Docking Station Set

Acer Nitro V 15.6 FHD 144Hz Gaming Laptop, Intel i7-13620H, 32GB DDR5, 1TB SSD, NVIDIA GeForce RTX 4060, Keyboard Backlight, Wi-Fi 6, HD Webcam, Windows 11 Home, Black, 256GB Docking Station Set

(105)
$1,655.10
FREE delivery Wed, Jun 18
Loading...
NIDOO Laptop Sleeve 15.6 inch Computer Bag for 15.6" Lenovo Legion 5 / Legion Slim 7 / ThinkPad T15 E15 / 16" Legion 7i / Legion 5 Pro/IdeaPad 3i / 16.1" Gaming 16 / Acer Dell Carrying Case, Black

NIDOO Laptop Sleeve 15.6 inch Computer Bag for 15.6" Lenovo Legion 5 / Legion Slim 7 / ThinkPad T15 E15 / 16" Legion 7i / Legion 5 Pro/IdeaPad 3i / 16.1" Gaming 16 / Acer Dell Carrying Case, Black

(124)
$24.99
FREE delivery Sat, Jun 21 on your first order
Loading...
Dell UltraSharp 24 Monitor - U2424H

Dell UltraSharp 24 Monitor - U2424H

(43)
$309.44$262.14
FREE delivery Aug 22 - 25Only 8 left in stock.
Loading...
Dell UltraSharp U2723QE 27" 4K UHD WLED LCD Monitor - 16:9 - Black, Silver EPEAT

Dell UltraSharp U2723QE 27" 4K UHD WLED LCD Monitor - 16:9 - Black, Silver EPEAT

(13)
$699.99$650.99
FREE delivery Tue, Oct 7
50+ bought in past month
Loading...
Logitech M185 Wireless Mouse, 2.4GHz with USB Mini Receiver, 12-Month Battery Life, 1000 DPI Optical Tracking, Ambidextrous, Compatible with PC, Mac, Laptop - Black

Logitech M185 Wireless Mouse, 2.4GHz with USB Mini Receiver, 12-Month Battery Life, 1000 DPI Optical Tracking, Ambidextrous, Compatible with PC, Mac, Laptop - Black

(48,912)
$15.99$12.79
FREE delivery Wed, Feb 18 on your first order
1K+ bought in past month
Loading...
Logitech G203 Wired Gaming Mouse, 8,000 DPI, Rainbow Optical Effect LIGHTSYNC RGB, 6 Programmable Buttons, On-Board Memory, Screen Mapping, PC/Mac Computer and Laptop Compatible - Black
Best Seller

Logitech G203 Wired Gaming Mouse, 8,000 DPI, Rainbow Optical Effect LIGHTSYNC RGB, 6 Programmable Buttons, On-Board Memory, Screen Mapping, PC/Mac Computer and Laptop Compatible - Black

(17,871)
$27.98$22.38
FREE delivery Tue, Oct 14 on your first order
500+ bought in past month
Loading...
Logitech G305 Lightspeed Wireless Gaming Mouse, Hero 12K Sensor, 12,000 DPI, Lightweight, 6 Programmable Buttons, 250h Battery Life, On-Board Memory, PC/Mac - Black

Logitech G305 Lightspeed Wireless Gaming Mouse, Hero 12K Sensor, 12,000 DPI, Lightweight, 6 Programmable Buttons, 250h Battery Life, On-Board Memory, PC/Mac - Black

(35,879)
$49.99$44.99
FREE delivery Mon, Jan 26
1K+ bought in past month
Loading...
Logitech G502 Hero High Performance Wired Gaming Mouse, Hero 25K Sensor, 25,600 DPI, RGB, Adjustable Weights, 11 Programmable Buttons, On-Board Memory, PC/Mac, Black

Logitech G502 Hero High Performance Wired Gaming Mouse, Hero 25K Sensor, 25,600 DPI, RGB, Adjustable Weights, 11 Programmable Buttons, On-Board Memory, PC/Mac, Black

(55,508)
$49.98$44.98
FREE delivery Thu, Jan 29
2K+ bought in past month
Loading...
Freenove Ultimate Starter Kit for BBC micro bit (V2 Included), 316-Page Detailed Tutorial, 225 Items, 44 Projects, Blocks and Python Code

Freenove Ultimate Starter Kit for BBC micro bit (V2 Included), 316-Page Detailed Tutorial, 225 Items, 44 Projects, Blocks and Python Code

(382)
$94.95
PrimeFREE delivery Sat, Jun 14