Skip to content

Instantly share code, notes, and snippets.

View skt7's full-sized avatar

Shivam Thakkar skt7

  • Mumbai, Maharastra, India
  • X @pyskt7
View GitHub Profile
@skt7
skt7 / detect.py
Last active March 5, 2021 15:35
using image_to_boxes function to see how tesseract detect contours
"""
Created on Fri Apr 20 22:21:42 2018
@author: skt
"""
import pytesseract
import cv2
img = cv2.imread('HTYux.jpg')
@skt7
skt7 / useful_pandas_snippets.py
Created April 13, 2018 22:53 — forked from yjw868/useful_pandas_snippets.py
Useful Pandas Snippets
# 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!
img = 'colors.jpg'
clusters = 5
dc = DominantColors(img, clusters)
colors = dc.dominantColors()
dc.plotClusters()
@skt7
skt7 / hist-run.py
Last active January 26, 2018 21:13
img = 'colors.jpg'
clusters = 5
dc = DominantColors(img, clusters)
colors = dc.dominantColors()
dc.plotHistogram()
@skt7
skt7 / hist.py
Created January 26, 2018 21:08
Plotting order of dominance
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)
@skt7
skt7 / cluster-viz.py
Last active January 26, 2018 21:12
Python code to see which cluster each pixel belong to.
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
@skt7
skt7 / out.txt
Created January 26, 2018 20:38
Output of dominant-colors.py for colors.jpg
[[234 32 67]
[253 236 175]
[199 191 48]
[162 211 156]
[240 98 70]]
@skt7
skt7 / 3d-plot.py
Created January 26, 2018 20:31
3D plot for image pixels using python matplotlib
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)
@skt7
skt7 / dominat-colors.py
Last active November 10, 2022 15:04
Dominant Colors in an image using python opencv and scikit-learn
import cv2
from sklearn.cluster import KMeans
class DominantColors:
CLUSTERS = None
IMAGE = None
COLORS = None
LABELS = None