Skip to content

Commit

Permalink
Added Image Processing
Browse files Browse the repository at this point in the history
  • Loading branch information
bytesByHarsh committed Jan 15, 2022
1 parent e799f91 commit 771c089
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 1 deletion.
18 changes: 17 additions & 1 deletion Python/AutoPaint/PaintUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import cv2,imutils

from ProcessImage import ProcessImage

class PaintUI(QtWidgets.QMainWindow):
def __init__(self):
super(PaintUI,self).__init__() #Call the inherited classes __init__ method
Expand All @@ -16,9 +18,11 @@ def __init__(self):
self.cannyThreshold1 = 0
self.cannyThreshold2 = 100

self.processImage = ProcessImage()

# Signal and Slots
self.loadButton.clicked.connect(self.loadImage)
self.saveButton.clicked.connect(self.label.clear)
self.saveButton.clicked.connect(self.saveImage)
self.thresh1Slider.valueChanged['int'].connect(self.thresholdValue1)
self.thresh2Slider.valueChanged['int'].connect(self.thresholdValue2)

Expand All @@ -32,6 +36,7 @@ def loadImage(self):
if not self.fileName:
return
self.img = cv2.imread(self.fileName)
self.processImage.loadImage(self.img)
self.setPhoto(self.img)

def setPhoto(self,image):
Expand All @@ -49,10 +54,21 @@ def setPhoto(self,image):
def thresholdValue1(self,value):
self.cannyThreshold1 = value
print(f"Thresh 1: {value}")
self.update()

def thresholdValue2(self,value):
self.cannyThreshold2 = value
print(f"Thresh 2: {value}")
self.update()

def update(self):
if not self.fileName:
print("Select Image First")
return
self.setPhoto(self.processImage.refreshImage(self.cannyThreshold1,self.cannyThreshold2))

def saveImage(self):
cv2.imwrite("test.jpg",self.tmp)



Expand Down
65 changes: 65 additions & 0 deletions Python/AutoPaint/ProcessImage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import pyautogui
import time
import cv2

pyautogui.PAUSE = 0.01

class ProcessImage():
def __init__(self):
self.canvas_start_ratio_x = 10.0/1920
self.canvas_start_ratio_y = 180.0/1080

self.canvas_size_ratio_x = 1070.0/1920
self.canvas_size_ratio_y = 670.0/1080

self.screenWidth, self.screenHeight = pyautogui.size()

self.canvas_start_x = self.screenWidth*self.canvas_start_ratio_x
self.canvas_start_y = self.screenHeight*self.canvas_start_ratio_y

self.canvas_end_x = self.canvas_start_x + self.canvas_size_ratio_x*self.screenWidth
self.canvas_end_y = self.canvas_start_y + self.canvas_size_ratio_y*self.screenHeight

self.img = None

def loadImage(self,img):
self.img = img.copy()
(self.h,self.w) = self.img.shape[:2]

if self.h>self.w:
self.img = self.image_resize(self.img,height=int(self.canvas_size_ratio_y*self.screenHeight))
else:
self.img = self.image_resize(self.img,width=int(self.canvas_size_ratio_x*self.screenWidth))

self.image_pre_process()
self.edge_detection()

def refreshImage(self,thesh1,thresh2):
self.edges = cv2.Canny(image=self.img_blur, threshold1=thesh1, threshold2=thresh2)
return self.edges

def image_resize(self,image, width = None, height = None, inter = cv2.INTER_AREA):
dim = None
(h, w) = image.shape[:2]
if width is None and height is None:
return None

if width is None:
r = height / float(h)
dim = (int(w * r), height)
else:
r = width / float(w)
dim = (width, int(h * r))
resized = cv2.resize(image, dim, interpolation = inter)
return resized

def image_pre_process(self):
self.img_gray = cv2.cvtColor(self.img, cv2.COLOR_BGR2GRAY)
self.img_blur = cv2.GaussianBlur(self.img_gray, (3,3), 0)

def edge_detection(self):
# self.sobelx = cv2.Sobel(src=self.img_blur, ddepth=cv2.CV_64F, dx=1, dy=0, ksize=5) # Sobel Edge
# self.sobely = cv2.Sobel(src=self.img_blur, ddepth=cv2.CV_64F, dx=0, dy=1, ksize=5) # Sobel Edge
# self.sobelxy = cv2.Sobel(src=self.img_blur, ddepth=cv2.CV_64F, dx=1, dy=1, ksize=5) # Combined X

self.edges = cv2.Canny(image=self.img_blur, threshold1=30, threshold2=50)

0 comments on commit 771c089

Please sign in to comment.