This file contains hidden or 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
""" | |
Created on Fri Apr 20 22:21:42 2018 | |
@author: skt | |
""" | |
import pytesseract | |
import cv2 | |
img = cv2.imread('HTYux.jpg') |
This file contains hidden or 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
# List unique values in a DataFrame column | |
# h/t @makmanalp for the updated syntax! | |
df['Column Name'].unique() | |
# Convert Series datatype to numeric (will error if column has non-numeric values) | |
# h/t @makmanalp | |
pd.to_numeric(df['Column Name']) | |
# Convert Series datatype to numeric, changing non-numeric values to NaN | |
# h/t @makmanalp for the updated syntax! |
This file contains hidden or 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
img = 'colors.jpg' | |
clusters = 5 | |
dc = DominantColors(img, clusters) | |
colors = dc.dominantColors() | |
dc.plotClusters() |
This file contains hidden or 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
img = 'colors.jpg' | |
clusters = 5 | |
dc = DominantColors(img, clusters) | |
colors = dc.dominantColors() | |
dc.plotHistogram() |
This file contains hidden or 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
import cv2 | |
import numpy as np | |
import matplotlib.pyplot as plt | |
class DominantColors: | |
def plotHistogram(self): | |
#labels form 0 to no. of clusters | |
numLabels = np.arange(0, self.CLUSTERS+1) |
This file contains hidden or 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
import matplotlib.pyplot as plt | |
from mpl_toolkits.mplot3d import Axes3D | |
class DominantColors: | |
def rgb_to_hex(self, rgb): | |
return '#%02x%02x%02x' % (int(rgb[0]), int(rgb[1]), int(rgb[2])) | |
def plotClusters(self): | |
#plotting |
This file contains hidden or 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
[[234 32 67] | |
[253 236 175] | |
[199 191 48] | |
[162 211 156] | |
[240 98 70]] |
This file contains hidden or 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
import matplotlib.pyplot as plt | |
from mpl_toolkits.mplot3d import Axes3D | |
import cv2 | |
#read image | |
img = cv2.imread('colors.jpg') | |
#convert from BGR to RGB | |
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) |
This file contains hidden or 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
import cv2 | |
from sklearn.cluster import KMeans | |
class DominantColors: | |
CLUSTERS = None | |
IMAGE = None | |
COLORS = None | |
LABELS = None | |