Created
September 20, 2017 12:55
-
-
Save orasik/2f5b7240ed4bf5a030fb67feb5fc02f6 to your computer and use it in GitHub Desktop.
[Python] OpenCV snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Showing openCV version | |
import cv2 | |
print("OpenCV version: %s" % cv2.__version__) | |
# Reading image and converting it to HSV | |
img = cv2.imread('img/test.jpg') | |
img = cv2.cvtColor(img, cv2.COLOR_BGR2HSV ) | |
plt.imshow(img) | |
# Reading files based on name or extension in a folder inside a loop | |
import glob | |
for filename in glob.glob("/path/to/*.json"): | |
print(filename) | |
# Showing progress bar for loops | |
from tqdm import * | |
for filename in tqdm(glob.glob("/path/to/*.json")): | |
print(filename) | |
# Display images inline in jupyter notebook | |
%matplotlib inline | |
# Show time spent in a function | |
%timeit myfunction() | |
# Split filename and extension from filepath | |
import os | |
title, ext = os.path.splitext(os.path.basename(pathAndFilename)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment