Center images
This commit is contained in:
parent
ee78037f17
commit
dc4cf5c222
Binary file not shown.
Before Width: | Height: | Size: 491 KiB |
@ -12,5 +12,5 @@ def run_server(port, directory):
|
|||||||
# Create the HTTP server
|
# Create the HTTP server
|
||||||
handler = http.server.SimpleHTTPRequestHandler
|
handler = http.server.SimpleHTTPRequestHandler
|
||||||
with socketserver.TCPServer(("", port), handler) as httpd:
|
with socketserver.TCPServer(("", port), handler) as httpd:
|
||||||
print(f"Serving at port {port}")
|
print(f"Serving cable images & files at port {port}")
|
||||||
httpd.serve_forever()
|
httpd.serve_forever()
|
||||||
|
@ -68,18 +68,21 @@ def find_file_noext(directory, prefix="part-hires"):
|
|||||||
#print(directory, matching_files)
|
#print(directory, matching_files)
|
||||||
return matching_files
|
return matching_files
|
||||||
|
|
||||||
def rotate_and_crop_image(path, image_name):
|
def rotate_and_crop_image(path, image_name, force_rotate=False):
|
||||||
# Open the image file
|
# Open the image file
|
||||||
image_path = path + "/" + image_name
|
image_path = path + "/" + image_name
|
||||||
with Image.open(image_path) as img:
|
with Image.open(image_path) as img:
|
||||||
# Check if the image is wider than it is tall
|
# Check if the image is wider than it is tall
|
||||||
if img.width > img.height * 1.2:
|
if force_rotate or img.width > img.height * 1.2:
|
||||||
# Rotate the image by 90 degrees counter-clockwise
|
# Rotate the image by 90 degrees counter-clockwise
|
||||||
img = img.rotate(90, expand=True)
|
img = img.rotate(90, expand=True)
|
||||||
|
|
||||||
# Determine the size of the square (the length of the shorter side of the image)
|
# Determine the size of the square (the length of the shorter side of the image)
|
||||||
square_size = min(img.width, img.height)
|
square_size = min(img.width, img.height)
|
||||||
|
if img.height < img.width:
|
||||||
|
offset = (img.width - img.height)/2
|
||||||
|
img_cropped = img.crop((offset, 0, square_size+offset, square_size))
|
||||||
|
else:
|
||||||
# Crop the image to a square from the top
|
# Crop the image to a square from the top
|
||||||
img_cropped = img.crop((0, 0, square_size, square_size))
|
img_cropped = img.crop((0, 0, square_size, square_size))
|
||||||
|
|
||||||
@ -184,10 +187,10 @@ def parse(filename, output_dir, partnum, dstype, weburl):
|
|||||||
count += 1
|
count += 1
|
||||||
|
|
||||||
if os.path.exists(output_dir + "/found_part_hires"):
|
if os.path.exists(output_dir + "/found_part_hires"):
|
||||||
rotate_and_crop_image(output_dir, find_file_noext(output_dir, prefix="part-hires")[0])
|
rotate_and_crop_image(output_dir, find_file_noext(output_dir, prefix="part-hires")[0], force_rotate=(dstype == "Alphawire"))
|
||||||
img = weburl + find_file_noext(output_dir, prefix="thumbnail-part-hires")[0]
|
img = weburl + find_file_noext(output_dir, prefix="thumbnail-part-hires")[0]
|
||||||
elif len(find_file_noext(output_dir, prefix="part")) > 0:
|
elif len(find_file_noext(output_dir, prefix="part")) > 0:
|
||||||
rotate_and_crop_image(output_dir, find_file_noext(output_dir, prefix="part")[0])
|
rotate_and_crop_image(output_dir, find_file_noext(output_dir, prefix="part")[0], force_rotate=(dstype == "Alphawire"))
|
||||||
img = weburl + find_file_noext(output_dir, prefix="thumbnail-part")[0]
|
img = weburl + find_file_noext(output_dir, prefix="thumbnail-part")[0]
|
||||||
else:
|
else:
|
||||||
img = None
|
img = None
|
||||||
|
15
run.py
15
run.py
@ -67,6 +67,8 @@ ring_animation = None
|
|||||||
led_set_mode = None
|
led_set_mode = None
|
||||||
sensors = [0,0,0,0]
|
sensors = [0,0,0,0]
|
||||||
websocket_process = None
|
websocket_process = None
|
||||||
|
arm_updates = Queue()
|
||||||
|
animation_wait = False
|
||||||
|
|
||||||
def arm_start_callback(res):
|
def arm_start_callback(res):
|
||||||
fprint("Arm action complete.")
|
fprint("Arm action complete.")
|
||||||
@ -310,9 +312,10 @@ def setup_server(pool):
|
|||||||
global to_server_queue
|
global to_server_queue
|
||||||
global from_server_queue
|
global from_server_queue
|
||||||
global websocket_process
|
global websocket_process
|
||||||
|
global arm_updates
|
||||||
|
|
||||||
|
|
||||||
arm = Rob(config)
|
arm = Rob(config, arm_updates)
|
||||||
if real:
|
if real:
|
||||||
pool.apply_async(ur5_control.powerup_arm, (arm,), callback=arm_start_callback, error_callback=handle_error)
|
pool.apply_async(ur5_control.powerup_arm, (arm,), callback=arm_start_callback, error_callback=handle_error)
|
||||||
else:
|
else:
|
||||||
@ -443,6 +446,9 @@ def mainloop_server(pool):
|
|||||||
global cable_list_state
|
global cable_list_state
|
||||||
global scan_value
|
global scan_value
|
||||||
global oldmode
|
global oldmode
|
||||||
|
global arm_updates
|
||||||
|
global animation_wait
|
||||||
|
|
||||||
if mode != oldmode:
|
if mode != oldmode:
|
||||||
print(" ***** Running mode:", mode, "***** ")
|
print(" ***** Running mode:", mode, "***** ")
|
||||||
oldmode = mode
|
oldmode = mode
|
||||||
@ -454,8 +460,14 @@ def mainloop_server(pool):
|
|||||||
|
|
||||||
# do every loop!
|
# do every loop!
|
||||||
if ring_animation is not None and ledsys.mode != "idle" and real:
|
if ring_animation is not None and ledsys.mode != "idle" and real:
|
||||||
|
if not animation_wait and not arm_updates.empty():
|
||||||
|
arm_updates.get()
|
||||||
ledsys.mainloop(None, ring_animation)
|
ledsys.mainloop(None, ring_animation)
|
||||||
elif ring_animation is not None and real:
|
elif ring_animation is not None and real:
|
||||||
|
if animation_wait:
|
||||||
|
if not arm_updates.empty():
|
||||||
|
animation_wait = False
|
||||||
|
val = arm_updates.get()
|
||||||
ledsys.mainloop(led_set_mode, ring_animation)
|
ledsys.mainloop(led_set_mode, ring_animation)
|
||||||
led_set_mode = None
|
led_set_mode = None
|
||||||
else:
|
else:
|
||||||
@ -475,6 +487,7 @@ def mainloop_server(pool):
|
|||||||
fprint("Getting cable index " + str(counter) + " and scanning...")
|
fprint("Getting cable index " + str(counter) + " and scanning...")
|
||||||
arm_state = "GET"
|
arm_state = "GET"
|
||||||
ring_animation = counter
|
ring_animation = counter
|
||||||
|
animation_wait=True
|
||||||
led_set_mode = "GrabA"
|
led_set_mode = "GrabA"
|
||||||
#ur5_control.to_camera(arm, counter)
|
#ur5_control.to_camera(arm, counter)
|
||||||
#arm_ready = True
|
#arm_ready = True
|
||||||
|
@ -20,8 +20,8 @@ class Rob():
|
|||||||
robot = None
|
robot = None
|
||||||
#offset_x, offset_y, offset_z = (0, 0, 0.14) # Tool offset
|
#offset_x, offset_y, offset_z = (0, 0, 0.14) # Tool offset
|
||||||
#
|
#
|
||||||
pos_updates = Queue()
|
|
||||||
def __init__(self, config):
|
def __init__(self, config, pos_queue=Queue()):
|
||||||
self.config = config
|
self.config = config
|
||||||
armc = config["arm"]
|
armc = config["arm"]
|
||||||
self.ip = armc["ip"]
|
self.ip = armc["ip"]
|
||||||
@ -33,6 +33,7 @@ class Rob():
|
|||||||
self.limb2 = limbs["limb2"]
|
self.limb2 = limbs["limb2"]
|
||||||
self.limb3 = limbs["limb3"]
|
self.limb3 = limbs["limb3"]
|
||||||
self.limb_wrist = limbs["limb_wrist"]
|
self.limb_wrist = limbs["limb_wrist"]
|
||||||
|
self.pos_updates = pos_queue
|
||||||
#self.init_arm()
|
#self.init_arm()
|
||||||
|
|
||||||
def ping(host):
|
def ping(host):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user