Draw a Forest of Random Tree Objects with Python OpenCV - Classes and OOP Practice for Beginners
Python Simplified
@pythonsimplifiedAbout
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
Boost Your Python Graphics Skills Today
AI-recommended products based on this video

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

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)

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)

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

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 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 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

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

Dell UltraSharp 24 Monitor - U2424H

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

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 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

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 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




















