printer.sendPackage(points)
buffer_time = time.time()
-
Draw.drawImage(img, printer)
cv2.imshow('cum', processedImg)
-{"open": 1, "close": 10, "erode": 10, "dilate": 12, "saturationMin": 124}
\ No newline at end of file
+{"open": 1, "close": 19, "erode": 17, "dilate": 22, "saturationMin": 177}
\ No newline at end of file
import serial, time
-from settings import frameSettings
+from settings import printerSettings
from utils import MatrixConversion, Geometry, Gcode, PrinterUtils
class Printer():
self.position = (0,0)
self.sendSpike = False
self.sendMovement = True
- self.settings = frameSettings.frameSettings()
+ self.settings = printerSettings.PrinterSettings()
self.coeffs = MatrixConversion.find_coeffs(self.settings.image_frame.corners, self.settings.laser_frame.corners)
try: self.printerSerial = serial.Serial(PrinterCOM, 115200, timeout = 25)
except: print("Connection Failure")
if not self.sendMovement: return
if len(points) > 4: points = points[:4]
adjustedPoints = list(map(self.adjustXY, points))
+ adjustedPoints = PrinterUtils.addOffsets(adjustedPoints, (self.settings.xOffset, self.settings.yOffset))
adjustedPoints = PrinterUtils.reverseBoundX(adjustedPoints, self.max_X) #Reverse X bound
package = Gcode.buildGcodePackage(adjustedPoints, (self.max_X, self.max_Y), self.sendSpike)
-{"laser_frame": [[158, 64], [418, 70], [449, 263], [131, 254]], "image_frame": [[50, 50], [100, 50], [100, 100], [50, 100]]}
\ No newline at end of file
+{"laser_frame": [[142, 52], [412, 57], [451, 263], [104, 258]], "image_frame": [[50, 50], [100, 50], [100, 100], [50, 100]], "xOffset": 10, "yOffset": -10}
\ No newline at end of file
import Printer, time, cv2
import numpy as np
-from utils import Gcode, Detector, MaskProcessing, PrinterUtils
+from utils import Gcode, Detector, MaskProcessing
from User_Interface import Sliders
-tst = [
- (50, 100),
- (175, 10),
- (60, 95)
-]
+cap = cv2.VideoCapture(0)
+detector = Detector.InitializeBlobDetector()
+cv2.namedWindow('image')
+sliders = Sliders.Sliders('image')
+printer = Printer.Printer('COM4', (200, 200))
-res = PrinterUtils.reverseBoundX(tst, 200)
+while 1:
+ ret, img = cap.read()
-print(res)
\ No newline at end of file
+ colorMask = MaskProcessing.GetColorMask(img, sliders)
+ res = MaskProcessing.ProcessImageMask(colorMask, img, sliders)
+
+ keyPoints = detector.detect(res)
+ img = cv2.drawKeypoints(img, keyPoints, np.array([]), (255, 0, 0), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
+
+ if keyPoints:
+ points = [xy.pt for xy in keyPoints]
+ printer.sendPackage(points)
+
+
+ # print('-------PACKAGE COUNT: %d-------'%(len(points)))
+ # print(Gcode.buildGcodePackage(points, printer, False))
+
+ cv2.imshow('image', res)
+ cv2.imshow('color', colorMask)
+ cv2.imshow('cum', img)
+
+ command = cv2.waitKey(10) & 0xFF
+ if command == ord('q'): break
\ No newline at end of file
return True
elif command == ord('d'):
enableDots = not enableDots
+ elif command == ord('c'):
+ printer.settings.xOffset -= 1
+ elif command == ord('v'):
+ printer.settings.xOffset += 1
+ elif command == ord('u'):
+ printer.settings.yOffset -= 1
+ elif command == ord('i'):
+ printer.settings.yOffset += 1
elif command == ord('s'):
printer.sendMovement = not printer.sendMovement
elif command == ord('f'):
print(printer.sendSpike)
elif command == ord('h'):
printer.home()
- elif command == ord('c'):
+ elif command == ord('g'):
printer.callibrate()
elif command == ord('z'):
printer.raiseZ()
x,y = printer.settings.laser_frame.getCenter()
cv2.circle(frame, (int(x), int(y)), 4, (0, 255, 0), 1)
cx,cy = printer.position
- cv2.putText(frame, str((round(cx),round(cy))), (20, 450), cv2.FONT_HERSHEY_COMPLEX, 0.5, (255, 255, 255))
+ cv2.putText(frame, 'Position', (20, 450), cv2.FONT_HERSHEY_COMPLEX, 0.5, (255, 255, 255))
+ cv2.putText(frame, 'Offsets', (20, 470), cv2.FONT_HERSHEY_COMPLEX, 0.5, (255, 255, 255))
+ cv2.putText(frame, str((round(cx),round(cy))), (100, 450), cv2.FONT_HERSHEY_COMPLEX, 0.5, (255, 255, 255))
+ cv2.putText(frame, str((printer.settings.xOffset, printer.settings.yOffset)), (100, 470), cv2.FONT_HERSHEY_COMPLEX, 0.5, (255, 255, 255))
+
if printer.sendSpike:
- cv2.circle(frame, (150, 450), 10, (0, 255, 0), 25)
+ cv2.circle(frame, (40, 400), 10, (0, 255, 0), 25)
else:
- cv2.circle(frame, (150, 450), 10, (0, 0, 255), 25)
+ cv2.circle(frame, (40, 400), 10, (0, 0, 255), 25)
import cv2
from settings import maskSettings
-openVal = 1
-closeVal = 11
-erode = 10
-dilate = 8
-saturationMin = 170
-
class Sliders:
def nothing(self, x): pass
from User_Interface import BoxFrame
SettingsName = 'Settings.json'
-class frameSettings:
+class PrinterSettings:
def __init__(self):
with open(SettingsName, 'r') as file:
data = json.load(file)
self.laser_frame = BoxFrame.BoxFrame(laser_frame)
self.image_frame = BoxFrame.BoxFrame(image_frame)
+ self.xOffset = data['xOffset']
+ self.yOffset = data['yOffset']
def saveSettings(self):
jsonDict = {
"laser_frame": self.laser_frame.corners,
- "image_frame": self.image_frame.corners
+ "image_frame": self.image_frame.corners,
+ "xOffset": self.xOffset,
+ "yOffset": self.yOffset
}
with open(SettingsName, 'w') as file:
json.dump(jsonDict, file)
from utils import Geometry
def buildGcodePackage(points, xyMax, withSpike):
- package = 'G0 F5000\n' #Set printer head speed
+ package = 'G0 F10000\n' #Set printer head speed
for point in points:
if Geometry.pointWithinBounds(point, xyMax):
x,y = point
package += 'G0 X{:.1f} Y{:.1f}\n'.format(x, y) #Positioning format
#Pnumatic trigger on/off
if withSpike: package += 'M106 S300\n'
- package += 'G4 P500\n'
+ package += 'G4 P100\n'
if withSpike: package += 'M107\n'
package += 'G0 X0 Y0\n'
return package
\ No newline at end of file
def GetColorMask(img, sliders):
saturationMin = sliders.getMaskSettings().saturationMin
- lowerBound = np.array([0,saturationMin,20])
- upperBound = np.array([20,255,255])
+ lowerBound = np.array([0, saturationMin, 1])
+ upperBound = np.array([20, 255, 255])
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
return cv2.inRange(hsv, lowerBound, upperBound)
+def addOffsets(points, offsets):
+ x, y = offsets
+ return [(point[0] + x, point[1] + y) for point in points]
def reverseBoundX(points, xMax):
return [(xMax - point[0], point[1]) for point in points]