in middle of updating portion of code to a class

main
Tony 2021-12-22 13:12:40 -05:00
rodzic 7881ff69ef
commit 95386fd64a
3 zmienionych plików z 2173 dodań i 173 usunięć

Plik binarny nie jest wyświetlany.

Wyświetl plik

@ -115,18 +115,6 @@ idToLocDict = {0 :[2,21],
65:[2, 0]} 65:[2, 0]}
global xOffset
xOffset = 0
global yOffset
yOffset = 0
global rotation
rotation = 0
global cv2Overhead
global matPlotImage
global move
move = False
#################################################################################### ####################################################################################
# Should put these in a shared libary # Should put these in a shared libary
#################################################################################### ####################################################################################
@ -176,10 +164,59 @@ def pathToPoints3D(path, pointsPerCurve):
points3D.extend(curPoints3D[1:]) points3D.extend(curPoints3D[1:])
prevEnd = curPoints3D[-1] prevEnd = curPoints3D[-1]
return points3D return points3D
####################################################################################
def dist(p1, p2): ####################################################################################
return ((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2) ** 0.5 # OverlayGcode class
####################################################################################
class OverlayGcode:
def __init__(self, cv2Overhead):
self.xOffset = 0
self.yOffset = 0
self.rotation = 0
self.cv2Overhead = cv2Overhead
self.move = False
self.matPlotImage = plt.imshow(cv2.cvtColor(overlay, cv2.COLOR_BGR2RGB))
#overlay = overlaySvg(cv2Overhead)
fig, ax = plt.subplots()
fig.tight_layout()
plt.subplots_adjust(bottom=0.01, right = 0.99)
plt.axis([bedViewSizePixels,0, bedViewSizePixels, 0])
xAxes = plt.axes([0.01, 0.8, 0.2, 0.04])
self.xBox = TextBox(xAxes, "xOffset (in)", initial="0")
label = self.xBox.ax.get_children()[1] # label is a child of the TextBox axis
label.set_position([0.5,1]) # [x,y] - change here to set the position
label.set_horizontalalignment('center')
label.set_verticalalignment('bottom')
self.xBox.on_submit(self.onUpdateXOffset)
yAxes = plt.axes([0.01, 0.7, 0.2, 0.04])
self.yBox = TextBox(yAxes, "yOffset (in)", initial="0")
label = self.yBox.ax.get_children()[1] # label is a child of the TextBox axis
label.set_position([0.5,1]) # [x,y] - change here to set the position
label.set_horizontalalignment('center')
label.set_verticalalignment('bottom')
self.yBox.on_submit(self.onUpdateYOffset)
rAxes = plt.axes([0.01, 0.6, 0.2, 0.04])
self.rBox = TextBox(rAxes, "rotation (deg)", initial="0")
label = self.rBox.ax.get_children()[1] # label is a child of the TextBox axis
label.set_position([0.5,1]) # [x,y] - change here to set the position
label.set_horizontalalignment('center')
label.set_verticalalignment('bottom')
self.rBox.on_submit(self.onUpdateRotation)
cid = fig.canvas.mpl_connect('button_press_event', self.onclick)
cid = fig.canvas.mpl_connect('button_release_event', self.onrelease)
cid = fig.canvas.mpl_connect('motion_notify_event', self.onmove)
def scalePoints(points, scaleX, scaleY): def scalePoints(points, scaleX, scaleY):
for point in points: for point in points:
@ -243,36 +280,27 @@ def overlaySvg(image, xOff = 0, yOff = 0, rotation = 0):
return overlay return overlay
def updateXOffset(text): def onUpdateXOffset(text):
global xOffset if self.xOffset == float(text):
global yOffset
global rotation
global cv2Overhead
if xOffset == float(text):
return return
xOffset = float(text) self.xOffset = float(text)
overlay = overlaySvg(cv2Overhead, xOffset, yOffset, rotation) overlay = overlaySvg(self.cv2Overhead, self.xOffset, self.yOffset, self.rotation)
matPlotImage.set_data(cv2.cvtColor(overlay, cv2.COLOR_BGR2RGB)) matPlotImage.set_data(cv2.cvtColor(overlay, cv2.COLOR_BGR2RGB))
matPlotImage.figure.canvas.draw() matPlotImage.figure.canvas.draw()
def updateYOffset(text): def onUpdateYOffset(text):
global xOffset if self.yOffset == float(text):
global yOffset
global rotation
global cv2Overhead
if yOffset == float(text):
return return
yOffset = float(text) self.yOffset = float(text)
overlay = overlaySvg(cv2Overhead, xOffset, yOffset, rotation) overlay = overlaySvg(self.cv2Overhead, self.xOffset, self.yOffset, self.rotation)
matPlotImage.set_data(cv2.cvtColor(overlay, cv2.COLOR_BGR2RGB)) matPlotImage.set_data(cv2.cvtColor(overlay, cv2.COLOR_BGR2RGB))
matPlotImage.figure.canvas.draw() matPlotImage.figure.canvas.draw()
def updateRotation(text): def onUpdateRotation(text):
global rotation if self.rotation == float(text):
if rotation == float(text):
return return
rotation = float(text) self.rotation = float(text)
overlay = overlaySvg(cv2Overhead, xOffset, yOffset, rotation) overlay = overlaySvg(self.cv2Overhead, self.xOffset, self.yOffset, self.rotation)
matPlotImage.set_data(cv2.cvtColor(overlay, cv2.COLOR_BGR2RGB)) matPlotImage.set_data(cv2.cvtColor(overlay, cv2.COLOR_BGR2RGB))
matPlotImage.figure.canvas.draw() matPlotImage.figure.canvas.draw()
@ -285,15 +313,7 @@ def onclick(event):
move = False move = False
def onrelease(event): def onrelease(event):
global cv2Overhead
global matPlotImage global matPlotImage
global xBox
global yBox
global rBox
global xOffset
global yOffset
global rotation
global move
#If clicking outside region, or mouse moved since released then return #If clicking outside region, or mouse moved since released then return
if event.x < 260 or move == True: if event.x < 260 or move == True:
@ -302,19 +322,19 @@ def onrelease(event):
if event.button == MouseButton.RIGHT: if event.button == MouseButton.RIGHT:
xIn = pixelsToOrigin[0] / bedViewSizePixels * bedSize.X xIn = pixelsToOrigin[0] / bedViewSizePixels * bedSize.X
yIn = pixelsToOrigin[1] / bedViewSizePixels * bedSize.Y yIn = pixelsToOrigin[1] / bedViewSizePixels * bedSize.Y
rotation = math.atan2(yIn - yOffset, xIn - xOffset) self.rotation = math.atan2(yIn - self.yOffset, xIn - self.xOffset)
rotation = rotation * 180 / math.pi self.rotation = self.rotation * 180 / math.pi
else: else:
xOffset = pixelsToOrigin[0] / bedViewSizePixels * bedSize.X self.xOffset = pixelsToOrigin[0] / bedViewSizePixels * bedSize.X
yOffset = pixelsToOrigin[1] / bedViewSizePixels * bedSize.Y self.yOffset = pixelsToOrigin[1] / bedViewSizePixels * bedSize.Y
overlay = overlaySvg(cv2Overhead, xOffset, yOffset, rotation) overlay = overlaySvg(self.cv2Overhead, self.xOffset, self.yOffset, self.rotation)
matPlotImage.set_data(cv2.cvtColor(overlay, cv2.COLOR_BGR2RGB)) matPlotImage.set_data(cv2.cvtColor(overlay, cv2.COLOR_BGR2RGB))
matPlotImage.figure.canvas.draw() matPlotImage.figure.canvas.draw()
xBox.set_val(str(xOffset)) self.xBox.set_val(str(self.xOffset))
yBox.set_val(str(yOffset)) self.yBox.set_val(str(self.yOffset))
rBox.set_val(str(rotation)) self.rBox.set_val(str(self.rotation))
def crop_half_vertically(img): def crop_half_vertically(img):
#cropped_img = image[,int(image.shape[1]/2):int(image.shape[1])] #cropped_img = image[,int(image.shape[1]/2):int(image.shape[1])]
@ -487,12 +507,6 @@ cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 800)
frame = cv2.imread('cnc3.jpeg') frame = cv2.imread('cnc3.jpeg')
img = cv2.imread('cnc3.jpeg') img = cv2.imread('cnc3.jpeg')
# load the image, clone it for cv2Overhead, and then convert it to grayscale
global cv2Overhead
cv2Overhead = frame.copy()
####################################################################### #######################################################################
# Get grayscale image above threshold # Get grayscale image above threshold
####################################################################### #######################################################################
@ -563,44 +577,9 @@ cv2.waitKey()
############################################################# #############################################################
cv2Overhead = cv2.warpPerspective(frame, bedPixelToPhysicalLoc, (frame.shape[1], frame.shape[0])) cv2Overhead = cv2.warpPerspective(frame, bedPixelToPhysicalLoc, (frame.shape[1], frame.shape[0]))
cv2Overhead = cv2.resize(cv2Overhead, (bedViewSizePixels, bedViewSizePixels)) cv2Overhead = cv2.resize(cv2Overhead, (bedViewSizePixels, bedViewSizePixels))
overlay = overlaySvg(cv2Overhead) GCodeOverlay = OverlayGcode(cv2Overhead)
fig, ax = plt.subplots()
fig.tight_layout()
plt.subplots_adjust(bottom=0.01, right = 0.99)
plt.axis([bedViewSizePixels,0, bedViewSizePixels, 0])
matPlotImage = plt.imshow(cv2.cvtColor(overlay, cv2.COLOR_BGR2RGB))
xAxes = plt.axes([0.01, 0.8, 0.2, 0.04])
global xBox
xBox = TextBox(xAxes, "xOffset (in)", initial="0")
label = xBox.ax.get_children()[1] # label is a child of the TextBox axis
label.set_position([0.5,1]) # [x,y] - change here to set the position
label.set_horizontalalignment('center')
label.set_verticalalignment('bottom')
xBox.on_submit(updateXOffset)
yAxes = plt.axes([0.01, 0.7, 0.2, 0.04])
global yBox
yBox = TextBox(yAxes, "yOffset (in)", initial="0")
label = yBox.ax.get_children()[1] # label is a child of the TextBox axis
label.set_position([0.5,1]) # [x,y] - change here to set the position
label.set_horizontalalignment('center')
label.set_verticalalignment('bottom')
yBox.on_submit(updateYOffset)
rAxes = plt.axes([0.01, 0.6, 0.2, 0.04])
global rBox
rBox = TextBox(rAxes, "rotation (deg)", initial="0")
label = rBox.ax.get_children()[1] # label is a child of the TextBox axis
label.set_position([0.5,1]) # [x,y] - change here to set the position
label.set_horizontalalignment('center')
label.set_verticalalignment('bottom')
rBox.on_submit(updateRotation)
cid = fig.canvas.mpl_connect('button_press_event', onclick)
cid = fig.canvas.mpl_connect('button_release_event', onrelease)
cid = fig.canvas.mpl_connect('motion_notify_event', onmove)
plt.show() plt.show()

2021
test.nc 100644

Plik diff jest za duży Load Diff