Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ preprocessing/preprocessingImages/images/
.vs/
machineLearning/Object-Classification-and-Detection/Keras-Sandbox/simple-image-classification-model/pyimagesearch/__pycache__/
depthSensing/images/
*.jpg
*.pyc
10 changes: 5 additions & 5 deletions preprocessing/preprocessingImages/cornerDetection.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,17 @@ def get_contours(img):


# show the final points on a copy of the image
'''

img2 = img.copy()
for pt in coor_tuples:
cv.circle(img2, tuple(reversed(pt)), 3, (0, 0, 255), -1)
cv.imshow('Image with main corners', img2)
cv.waitKey(0)
'''


return coor_tuples


# img = cv.imread("test.jpg")
# corners = get_contours(img)
# print(corners)
img = cv.imread("dices-2164.jpg")
corners = get_contours(img)
print(corners)
Binary file removed preprocessing/preprocessingImages/float-0157.jpg
Binary file not shown.
54 changes: 54 additions & 0 deletions preprocessing/preprocessingImages/houghLine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import cv2
import numpy as np
from matplotlib import pyplot as plt
from PIL import Image
import PIL
#from preprocessing.preprocessingImages.threshCannyEdgeFunction import threshCanny

image_name = 'mask'
imgb = cv2.imread(image_name + '.jpg')

#obtain the threshold for Canny using the grayscale image
img_grayscale = cv2.cvtColor(imgb, cv2.COLOR_BGR2GRAY)
v = np.median(img_grayscale)
sigma = 0.33
#phi = 0.11
#first threshold

lower_thresh = int(max(0, (1.0 - sigma) * v))
upper_thresh = int(min(255, (1.0 + sigma) * v))
#second threshold

'''
if False:
lower_thresh = int(max(0, (1.0 - 2 * sigma) * v))
upper_thresh = int(min(255, v))
#third threshold
if False:
lower_thresh = int(max(0, (1.0 - 2 * sigma) * v))
upper_thresh = int(min(255, (1.0 + sigma) * v))
'''

#get the edge

edges = cv2.Canny(imgb, lower_thresh, upper_thresh)
#print(edges)
#edgesimg2 = PIL.Image.fromarray(edges)
#edgesimg2.save(image_name + '-threshold3' + '.jpg')

lines = cv2.HoughLines(edges, 20, np.pi/360, 2000)
for i in range(len(lines)):
for rho,theta in lines[i]:
#for rho,theta in lines[0]:
a = np.cos(theta)
b = np.sin(theta)
x0 = a*rho
y0 = b*rho
x1 = int(x0 + 1000*(-b))
y1 = int(y0 + 1000*(a))
x2 = int(x0 - 1000*(-b))
y2 = int(y0 - 1000*(a))

cv2.line(imgb,(x1,y1),(x2,y2),(0,0,255),2)

cv2.imwrite('mask-houghlines.jpg',imgb)
21 changes: 21 additions & 0 deletions preprocessing/preprocessingImages/maskImage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import cv2
import numpy as np
import matplotlib
from matplotlib.pyplot import imshow
from matplotlib import pyplot as plt

# white color mask
img = cv2.imread("dices-2164.jpg")
#converted = convert_hls(img)
image = cv2.cvtColor(img,cv2.COLOR_BGR2HSV)
lower = np.uint8([70, 150, 150])
upper = np.uint8([200, 255, 255])
white_mask = cv2.inRange(image, lower, upper)
# yellow color mask
lower = np.uint8([10, 0, 100])
upper = np.uint8([40, 255, 255])
yellow_mask = cv2.inRange(image, lower, upper)
# combine the mask
mask = cv2.bitwise_or(white_mask, yellow_mask)
result = img.copy()
cv2.imwrite("mask.jpg",white_mask)
Binary file removed preprocessing/preprocessingImages/test.jpg
Binary file not shown.
12 changes: 7 additions & 5 deletions preprocessing/preprocessingImages/threshCannyEdge.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from PIL import Image
import PIL

image_name = 'robot-0268'
image_name = 'mask'
imgb = cv2.imread(image_name + '.jpg')

#obtain the threshold for Canny using the grayscale image
Expand All @@ -13,10 +13,11 @@
sigma = 0.33
#phi = 0.11
#first threshold
if False:
lower_thresh = int(max(0, (1.0 - sigma) * v))
upper_thresh = int(min(255, (1.0 + sigma) * v))

lower_thresh = int(max(0, (1.0 - sigma) * v))
upper_thresh = int(min(255, (1.0 + sigma) * v))
#second threshold
'''
if False:
lower_thresh = int(max(0, (1.0 - 2 * sigma) * v))
upper_thresh = int(min(255, v))
Expand All @@ -25,9 +26,10 @@
upper_thresh = int(min(255, (1.0 + sigma) * v))

#TODO: set lower_thresh and upper_thresh lower
'''

#get the edge
edges = cv2.Canny(imgb, lower_thresh, upper_thresh)
print(edges)
edgesimg2 = PIL.Image.fromarray(edges)
edgesimg2.save(image_name + '-threshold3' + '.jpg')
edgesimg2.save(image_name + '-threshold' + '.jpg')