Skip to content

Instantly share code, notes, and snippets.

View zhunhung's full-sized avatar
👋
Nice to meet ya

Yong Zhun Hung zhunhung

👋
Nice to meet ya
View GitHub Profile
@zhunhung
zhunhung / DockerFile
Created January 18, 2020 02:29
Selenium Linux DockerFile
FROM ubuntu:latest
RUN apt-get update \
&& apt-get install -y python3-pip python3-dev \
&& cd /usr/local/bin \
&& ln -s /usr/bin/python3 python \
&& pip3 install --upgrade pip
# INSTALL DEPENDENCIES
RUN apt-get install -y curl unzip openjdk-8-jre-headless xvfb libxi6 libgconf-2-4
@zhunhung
zhunhung / test_selenium.py
Created January 13, 2020 13:04
Script to verify selenium works
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
CHROMEDRIVER_PATH = '/usr/local/bin/chromedriver'
WINDOW_SIZE = "1920,1080"
chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--window-size=%s" % WINDOW_SIZE)
chrome_options.add_argument('--no-sandbox')
@zhunhung
zhunhung / setup.sh
Last active June 30, 2022 11:29
Install packages for selenium, chrome and chromedriver in Linux VM
# Remove existing downloads and binaries so we can start from scratch.
sudo apt-get remove google-chrome-stable
rm ~/selenium-server-standalone-*.jar
rm ~/chromedriver_linux64.zip
sudo rm /usr/local/bin/chromedriver
sudo rm /usr/local/bin/selenium-server-standalone.jar
# Install dependencies.
sudo apt-get update
sudo apt-get install -y unzip openjdk-8-jre-headless xvfb libxi6 libgconf-2-4
@zhunhung
zhunhung / template_matching_unit.py
Created October 17, 2019 16:26
Match template to unit bounding box at different orientation
# load base image and template
img = cv2.imread(sample_img_path, 0)
template = cv2.imread(template_path, 0)
# canny edge detection to get edges of base image
edged = cv2.Canny(img, 50, 200)
# define the orientations
methods_arr = [('original',0), ('original',90), ('original',180), ('original',270),
('flipped',0), ('flipped',90), ('flipped',180), ('flipped',270)]
@zhunhung
zhunhung / contour_detection.py
Created October 17, 2019 15:13
Find contours in an image
# convert image to grayscale
imgray = cv2.cvtColor(img, cv.COLOR_BGR2GRAY)
# apply threshold
thresh = cv2.threshold(imgray, 127, 255, 0)[1]
# find contours
contours, hierarchy = cv.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
# draw contours on image
cv2.drawContours(img, contours, -1, (0, 255, 0), 3)
@zhunhung
zhunhung / color_segmentation.py
Last active October 17, 2019 15:01
Example of using OpenCV colour segmentation
color = [211, 227, 191]
# Convert our image from BGR to HSV
hsv_img = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
limit = np.uint8([[color]])
# Convert our color of choice to HSV as well
limit = cv2.cvtColor(limit,cv2.COLOR_BGR2HSV)[0][0]
mask = cv2.inRange(hsv_img, limit, limit)
# Filter for the colour
res = cv2.bitwise_and(img,img, mask= mask)