Image drawing for pixel finished
This commit is contained in:
parent
93dfdc8485
commit
3367286b41
Binary file not shown.
|
After Width: | Height: | Size: 100 KiB |
|
|
@ -1,43 +0,0 @@
|
|||
import matplotlib.pyplot as plt
|
||||
import dobot
|
||||
import time
|
||||
|
||||
DRAW_MODE = 1
|
||||
DRAW_SPEED = 1
|
||||
DRAW_SIZE = 40
|
||||
DRAW_DEPTH = -69
|
||||
DRAW_RES = 2
|
||||
|
||||
INIT_POSITION = [240, -10]
|
||||
|
||||
dobot.setQueuedCmdClear()
|
||||
dobot.setQueuedCmdStartExec()
|
||||
|
||||
dobot.setPTPJumpParams(5, 3, 1)
|
||||
|
||||
matrix = []
|
||||
for x in range(INIT_POSITION[0], INIT_POSITION[0]+DRAW_SIZE, DRAW_RES):
|
||||
for y in range(INIT_POSITION[1], INIT_POSITION[1]+DRAW_SIZE, DRAW_RES):
|
||||
matrix.append((x,y))
|
||||
|
||||
for point in matrix:
|
||||
dobot.setPTPCmd(1, point[0], point[1], DRAW_DEPTH+5, 0, 1)
|
||||
dobot.setPTPCmd(1, point[0], point[1], DRAW_DEPTH, 0, 1)
|
||||
dobot.setPTPCmd(1, point[0], point[1], DRAW_DEPTH+5, 0, 1)
|
||||
|
||||
dobot.setWaitCmd(3)
|
||||
time.sleep(0.8)
|
||||
|
||||
def pixel_draw(resolution):
|
||||
pass
|
||||
|
||||
def vector_draw(array):
|
||||
for vector in array:
|
||||
dobot.setCPCmd(DRAW_MODE, array.x, array.y, array.z, DRAW_SPEED, 1)
|
||||
|
||||
# Stop the current execution
|
||||
if input("Appuyez sur Entrer pour arrêter.") == "":
|
||||
dobot.setQueuedCmdForceStopExec()
|
||||
dobot.setQueuedCmdClear()
|
||||
|
||||
# Define current workspace
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
import matplotlib.pyplot as plt
|
||||
import dobot
|
||||
import time
|
||||
import cv2 as cv
|
||||
|
||||
# Drawing parameters
|
||||
DRAW_MODE = 1
|
||||
DRAW_SPEED = 1 # Drawing speed for
|
||||
DRAW_DEPTH = -67.8 # Initial height (null)
|
||||
DRAW_RES = 1 # Space between pixels
|
||||
THRESHOLD = 70 # Min. intensityfrom which a pixel must be drawn
|
||||
|
||||
INIT_POSITION = [210, -60]
|
||||
|
||||
dobot.setQueuedCmdClear()
|
||||
dobot.setQueuedCmdStartExec()
|
||||
|
||||
def pixel_draw(imagepath):
|
||||
|
||||
# Load Image
|
||||
im = cv.imread(imagepath)
|
||||
if im is None:
|
||||
print("Error: Image not found at", imagepath)
|
||||
exit()
|
||||
|
||||
# Resize Image
|
||||
im = cv.resize(im, (0, 0), fx = 0.05, fy = 0.05, interpolation=cv.INTER_LINEAR)
|
||||
|
||||
# Convert to Grayscale
|
||||
im = cv.cvtColor(im, cv.COLOR_BGR2GRAY)
|
||||
|
||||
# Window name in which image is displayed
|
||||
window_name = 'Display'
|
||||
|
||||
# Using cv2.imshow() method
|
||||
# Displaying the image
|
||||
im_display = cv.resize(im, (0, 0), fx = 10, fy = 10, interpolation=cv.INTER_LINEAR)
|
||||
print(im)
|
||||
print(im.shape[0], im.shape[1])
|
||||
cv.imshow(window_name, im_display)
|
||||
# waits for user to press any key
|
||||
# (this is necessary to avoid Python kernel form crashing)
|
||||
cv.waitKey(0)
|
||||
|
||||
for x in range(0, im.shape[0]-1):
|
||||
for y in range(0, im.shape[1]-1):
|
||||
value = im[x][y]
|
||||
print(value)
|
||||
|
||||
if value >= THRESHOLD:
|
||||
dobot.setPTPCmd(1, INIT_POSITION[0]+x*DRAW_RES, INIT_POSITION[1]+y*DRAW_RES, DRAW_DEPTH+2.5, 0, 1)
|
||||
dobot.setPTPCmd(1, INIT_POSITION[0]+x*DRAW_RES, INIT_POSITION[1]+y*DRAW_RES, DRAW_DEPTH-(value/255), 0, 1)
|
||||
dobot.setPTPCmd(1, INIT_POSITION[0]+x*DRAW_RES, INIT_POSITION[1]+y*DRAW_RES, DRAW_DEPTH+2.5, 0, 1)
|
||||
|
||||
#dobot.setWaitCmd(5)
|
||||
time.sleep(0.8)
|
||||
|
||||
def vector_draw(array):
|
||||
for vector in array:
|
||||
dobot.setCPCmd(DRAW_MODE, array.x, array.y, array.z, DRAW_SPEED, 1)
|
||||
|
||||
pixel_draw("C:/Users/alexl/Documents/Cours/S7/IT and Robotics/GrpC_Identikit/assets/sins.jpg")
|
||||
|
||||
# Stop the current execution
|
||||
"""if input("Appuyez sur Entrer pour arrêter.") == "":
|
||||
dobot.setQueuedCmdForceStopExec()
|
||||
dobot.setQueuedCmdClear()
|
||||
"""
|
||||
# Define current workspace
|
||||
Loading…
Reference in New Issue