Python
global _
folder, file name, functions,
const,
doc
read_all_image_in_folder
recursive = True
code
doc
manual progress bar for python based on number of images process.
code
doc
this code shows information about image
code
import unittest
for the functions: for example one time create file and then detected in between all operations in this function
def setUp(self):
def tearDown(self)
for the class:
@classmethod
def setUpClass(cls):
@classmethod
def tearDownClass(cls):
List files and folders
If you want to list directories which shows specific folder name in path in windows you can use
dir /s /b /o:n /ad "farshid" > farshid.txt
this command listed all directories which have "farshid" in the path and save it to the farshid.txt file
in python you can use below code to search and find specific folders and files
###################################################################################### import
import os
import glob
###################################################################################### config
root="C:\\farshid\\"
specific_directories=root+"/**/farshid/**/*.jpg"
path_dir_detection_check=""
###################################################################################### function
files= glob.glob(specific_directories, recursive=True)
for file in files:
b=file.rfind("farshid")
path_dir_detection=file[0:b-1]
if (path_dir_detection != path_dir_detection_check):
dirname = os.path.dirname(file)
print("******************************************************* Next Directories ************************")
print(dirname)
path_dir_detection_check=path_dir_detection
print(file)
The source code can be found in GitHub
make -j$(sysctl -n hw.physicalcpu)
shift+enter -> run selection
menue
code-> pereferences -> user snippets -> python.json
pip freeze > requirements.txt
extensions
Visual Studio IntelliCode
SSH FS
ext install Kelvin.vscode-sshfs
command+ shift+ p ->SSH SF: Create new SSH SF configuration
code ~/.zshrc
Bracket Pair Colorizer 2 => color (){}[] different color
Prettier - Code formatter => when you save. setting->(format on save)
indent-rainbow
shell => .code
Compare Folders
Command +p = all files -> if I press alt+ it open new tab the file
control + ` = open terminal
Command + o= open folder
Command + , = open setting
Command + /= #
shift+enter=run one line of code
option+shift+arrow down = duplicate line in code
command+ click mouse => go to function
command++ -> bigger
command+ shift +P
command+ K , command+ S => shourcuts
command+ L => select currnt line
command+ left/right arrow => start or end of line
command+ P => go to file in search
git config --global core.excludesfile ~/.gitignore
code ~/.gitignore
brew install pyenv
brew install poetry
pyenv install 3.7.5
pyenv global 3.7.5
poetry new "name of project"
-> go to folder
-> change python version if you want in the pyproject.toml
pyenv global 3.7.5
poetry new "pytorch_pretrained"
poetry install
pip install --upgrade pip
poetry add matplotlib numpy kubernetes=10.0.0 kfp=0.2.4 click=7.0.0 opencv-python opencv-contrib-python imutils pylint fastapi uvicorn python-dateutil seldon_core spacy sklearn torch torchvision jupyter pycocotools cython pyyaml==5.1
poetry remove torch torchvision
pip install --pre torch torchvision -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html
pip3 install matplotlib numpy kubernetes==10.0.0 kfp==0.2.4 click==7.0.0 opencv-python opencv-contrib-python imutils pylint fastapi uvicorn python-dateutil seldon_core spacy sklearn torch torchvision jupyter pycocotools cython
pip3 install pyyaml==5.1
pip3 install 'git+https://github.com/facebookresearch/detectron2.git'
pip3 install -U 'git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI'
poetry shell
jupyter notebook
pyenv
pyenv install
pyenv install 3.7.5
cd folder
pyenv global 3.7.5
pyenv versions
python -> you can see this environments
poetry install (pyproject.toml) ~/.bash , .bash_profile , .zshrc
poetry run which python
poetry run jupyter lab
pipenv install requests
pyenv virtualenvs cv-endpoint
pyenv activate cv-endpoint
====================
black python https://github.com/psf/black
The Uncompromising Code Formatter
pip install black
====================
pre-commit A framework for managing and maintaining multi-language pre-commit hooks.
pip install pre-commit
brew install pre-commit
.pre-commit-config.yaml
repos:
- repo: https://github.com/asottile/reorder_python_imports
rev: v1.8.0
hooks:
- id: reorder-python-imports
exclude: notebooks/
language_version: python3.7
- repo: https://github.com/ambv/black
rev: 19.10b0
hooks:
- id: black
exclude: notebooks/
language_version: python3.7
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.4.0
hooks:
- id: flake8
args: ['--ignore=E203,E266,E501,W503', '--max-line-length=88', '--max-complexity=15', '--select=B,C,E,F,W,T4,B9']
exclude: notebooks/
language_version: python3.7
pre-commit install
pre-commit run --all-files
git
make file
make check
code .
add path
import sys
sys.path.append(r'C: )
create Mat
bin_im = np.zeros((5,16))
bin_im = bin_im.astype(np.uint8)*255
contours, hierarchy = cv2.findContours(opening, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
np.savetxt("01-src.txt", im, fmt='%d', delimiter=', ', newline='\n', header='', footer='', comments='# ')
DLL
import ctypes
my_dll = r"C:\fffffff.dll"
lib = ctypes.windll.LoadLibrary(my_dll)
remove background or minimum form image
im = im - im.min()
time
e1 = cv2.getTickCount()
######
e2 = cv2.getTickCount()
time = (e2 - e1)/ cv2.getTickFrequency()
from scipy.signal import find_peaks
peaks, out = find_peaks(Nf, distance=25)
if peaks[0] < 25:
peaks = peaks[1:]
heights = Nf[peaks]
read matlab mat file to python
from scipy import io
res = io.loadmat(r'MatlabResults\results2.mat', struct_as_record=False, squeeze_me=True)
for k in res.keys():
print(k, res[k])
remove background or minimum form image
im = im - im.min()
time
e1 = cv2.getTickCount()
######
e2 = cv2.getTickCount()
time = (e2 - e1)/ cv2.getTickFrequency()
from scipy.signal import find_peaks
peaks, out = find_peaks(Nf, distance=25)
if peaks[0] < 25:
peaks = peaks[1:]
heights = Nf[peaks]
import sys
sys.path.append(r'C: )
import sys
sys.path.append(r'C: )
import sys
sys.path.append(r'C: )
import sys
sys.path.append(r'C: )