Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Poetry, requirements, formatters and linters #36

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[flake8]
max-line-length = 100
extend-ignore = E203, E704, W503
unused-arguments-ignore-abstract-functions = True
unused-arguments-ignore-overload-functions = True

ignore =
# An unused argument starting with an underscore
U101,
154 changes: 153 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,153 @@
.pylintrc
.idea/
.python-version

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
*.code-workspace
tests/data/*
temp/*

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/
contrib/vault/file/
/contrib/vault/keys/*.json
.local.env

# archives
*.zip
*.gz
*.tar
*.bz2
*.tgz
.DS_Store
23 changes: 23 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
SOURCES = 'Section \#1 - Basics' 'Section \#2 - Advanced' 'Section \#3 - Faces' 'Section \#4 - Capstone'

.DEFAULT_GOAL := help

help: ## Display this help screen
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: help

install: ## Install project dependencies
poetry install --no-interaction --no-ansi --without dev --no-root
.PHONY: install

format: ## Format the source code
poetry run black $(SOURCES)
poetry run isort $(SOURCES)
.PHONY: format

lint: ## Lint the source code
poetry run black --check $(SOURCES)
poetry run isort --check $(SOURCES)
poetry run flake8 $(SOURCES)

.PHONY: lint
21 changes: 18 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,24 @@ Notes and code used in my [**Python and OpenCV course**](https://youtu.be/oXlwWb

# Course Outline (with timestamps)
## 1. Installation
Besides installing OpenCV, we cover the installation of the following package:

[**`Caer`**](https://github.com/jasmcaus/caer/) is a *lightweight, high-performance* Vision library for high-performance AI research. It simplifies your approach towards Computer Vision by abstracting away unnecessary boilerplate code giving you the **flexibility** to quickly prototype deep learning models and research ideas.
### 1. Using Poetry

Install poetry using your package manager or [official guide](https://python-poetry.org/docs/#installation).

The easiest way to install all required dependencies is as follows:

```bash
$ pip install caer
make install
```

### 2. Using pip

```bash
$ pip install -r requirements.txt
```



## 2. Basic Concepts:
- Reading Images and Video ([0:04:12](https://www.youtube.com/watch?v=x3c8w2ruhjs&t=252s))
Expand Down Expand Up @@ -46,3 +57,7 @@ The images in the [Photos](https://github.com/jasmcaus/opencv-course/tree/master


The images in the [Faces](https://github.com/jasmcaus/opencv-course/tree/master/Resources/Faces) folder were procurred from a [repo](https://www.kaggle.com/dansbecker/5-celebrity-faces-dataset) on Kaggle.

# Contributors
Please make sure you have dev dependencies installed and your PR code formatted using `make format` and linted using
`make lint`
30 changes: 15 additions & 15 deletions Section #1 - Basics/basic_functions.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
#pylint:disable=no-member
# pylint:disable=no-member

import cv2 as cv

# Read in an image
img = cv.imread('../Resources/Photos/park.jpg')
cv.imshow('Park', img)
img = cv.imread("../Resources/Photos/park.jpg")
cv.imshow("Park", img)

# Converting to grayscale
gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
cv.imshow('Gray', gray)
cv.imshow("Gray", gray)

# Blur
blur = cv.GaussianBlur(img, (7,7), cv.BORDER_DEFAULT)
cv.imshow('Blur', blur)
# Blur
blur = cv.GaussianBlur(img, (7, 7), cv.BORDER_DEFAULT)
cv.imshow("Blur", blur)

# Edge Cascade
canny = cv.Canny(blur, 125, 175)
cv.imshow('Canny Edges', canny)
cv.imshow("Canny Edges", canny)

# Dilating the image
dilated = cv.dilate(canny, (7,7), iterations=3)
cv.imshow('Dilated', dilated)
dilated = cv.dilate(canny, (7, 7), iterations=3)
cv.imshow("Dilated", dilated)

# Eroding
eroded = cv.erode(dilated, (7,7), iterations=3)
cv.imshow('Eroded', eroded)
eroded = cv.erode(dilated, (7, 7), iterations=3)
cv.imshow("Eroded", eroded)

# Resize
resized = cv.resize(img, (500,500), interpolation=cv.INTER_CUBIC)
cv.imshow('Resized', resized)
resized = cv.resize(img, (500, 500), interpolation=cv.INTER_CUBIC)
cv.imshow("Resized", resized)

# Cropping
cropped = img[50:200, 200:400]
cv.imshow('Cropped', cropped)
cv.imshow("Cropped", cropped)
26 changes: 13 additions & 13 deletions Section #1 - Basics/contours.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
#pylint:disable=no-member
# pylint:disable=no-member

import cv2 as cv
import numpy as np

img = cv.imread('../Resources/Photos/cats.jpg')
cv.imshow('Cats', img)
img = cv.imread("../Resources/Photos/cats.jpg")
cv.imshow("Cats", img)

blank = np.zeros(img.shape, dtype='uint8')
cv.imshow('Blank', blank)
blank = np.zeros(img.shape, dtype="uint8")
cv.imshow("Blank", blank)

gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
cv.imshow('Gray', gray)
cv.imshow("Gray", gray)

blur = cv.GaussianBlur(gray, (5,5), cv.BORDER_DEFAULT)
cv.imshow('Blur', blur)
blur = cv.GaussianBlur(gray, (5, 5), cv.BORDER_DEFAULT)
cv.imshow("Blur", blur)

canny = cv.Canny(blur, 125, 175)
cv.imshow('Canny Edges', canny)
cv.imshow("Canny Edges", canny)

# ret, thresh = cv.threshold(gray, 125, 255, cv.THRESH_BINARY)
# cv.imshow('Thresh', thresh)

contours, hierarchies = cv.findContours(canny, cv.RETR_LIST, cv.CHAIN_APPROX_SIMPLE)
print(f'{len(contours)} contour(s) found!')
print(f"{len(contours)} contour(s) found!")

cv.drawContours(blank, contours, -1, (0,0,255), 1)
cv.imshow('Contours Drawn', blank)
cv.drawContours(blank, contours, -1, (0, 0, 255), 1)
cv.imshow("Contours Drawn", blank)

cv.waitKey(0)
cv.waitKey(0)
38 changes: 23 additions & 15 deletions Section #1 - Basics/draw.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,37 @@
#pylint:disable=no-member
# pylint:disable=no-member

import cv2 as cv
import numpy as np

blank = np.zeros((500,500,3), dtype='uint8')
cv.imshow('Blank', blank)
blank = np.zeros((500, 500, 3), dtype="uint8")
cv.imshow("Blank", blank)

# 1. Paint the image a certain colour
blank[200:300, 300:400] = 0,0,255
cv.imshow('Green', blank)
blank[200:300, 300:400] = 0, 0, 255
cv.imshow("Green", blank)

# 2. Draw a Rectangle
cv.rectangle(blank, (0,0), (blank.shape[1]//2, blank.shape[0]//2), (0,255,0), thickness=-1)
cv.imshow('Rectangle', blank)
cv.rectangle(blank, (0, 0), (blank.shape[1] // 2, blank.shape[0] // 2), (0, 255, 0), thickness=-1)
cv.imshow("Rectangle", blank)

# 3. Draw A circle
cv.circle(blank, (blank.shape[1]//2, blank.shape[0]//2), 40, (0,0,255), thickness=-1)
cv.imshow('Circle', blank)
cv.circle(blank, (blank.shape[1] // 2, blank.shape[0] // 2), 40, (0, 0, 255), thickness=-1)
cv.imshow("Circle", blank)

# 4. Draw a line
cv.line(blank, (100,250), (300,400), (255,255,255), thickness=3)
cv.imshow('Line', blank)
cv.line(blank, (100, 250), (300, 400), (255, 255, 255), thickness=3)
cv.imshow("Line", blank)

# 5. Write text
cv.putText(blank, 'Hello, my name is Jason!!!', (0,225), cv.FONT_HERSHEY_TRIPLEX, 1.0, (0,255,0), 2)
cv.imshow('Text', blank)

cv.waitKey(0)
cv.putText(
blank,
"Hello, my name is Jason!!!",
(0, 225),
cv.FONT_HERSHEY_TRIPLEX,
1.0,
(0, 255, 0),
2,
)
cv.imshow("Text", blank)

cv.waitKey(0)
Loading