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
|
||||
handler = http.server.SimpleHTTPRequestHandler
|
||||
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()
|
||||
|
@ -68,20 +68,23 @@ def find_file_noext(directory, prefix="part-hires"):
|
||||
#print(directory, 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
|
||||
image_path = path + "/" + image_name
|
||||
with Image.open(image_path) as img:
|
||||
# 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
|
||||
img = img.rotate(90, expand=True)
|
||||
|
||||
# Determine the size of the square (the length of the shorter side of the image)
|
||||
square_size = min(img.width, img.height)
|
||||
|
||||
# Crop the image to a square from the top
|
||||
img_cropped = img.crop((0, 0, square_size, square_size))
|
||||
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
|
||||
img_cropped = img.crop((0, 0, square_size, square_size))
|
||||
|
||||
# Save or display the image
|
||||
img_cropped.save(path + "/" + "thumbnail-" + image_name) # Save the cropped image
|
||||
@ -184,10 +187,10 @@ def parse(filename, output_dir, partnum, dstype, weburl):
|
||||
count += 1
|
||||
|
||||
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]
|
||||
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]
|
||||
else:
|
||||
img = None
|
||||
|
19
run.py
19
run.py
@ -67,6 +67,8 @@ ring_animation = None
|
||||
led_set_mode = None
|
||||
sensors = [0,0,0,0]
|
||||
websocket_process = None
|
||||
arm_updates = Queue()
|
||||
animation_wait = False
|
||||
|
||||
def arm_start_callback(res):
|
||||
fprint("Arm action complete.")
|
||||
@ -310,9 +312,10 @@ def setup_server(pool):
|
||||
global to_server_queue
|
||||
global from_server_queue
|
||||
global websocket_process
|
||||
global arm_updates
|
||||
|
||||
|
||||
arm = Rob(config)
|
||||
arm = Rob(config, arm_updates)
|
||||
if real:
|
||||
pool.apply_async(ur5_control.powerup_arm, (arm,), callback=arm_start_callback, error_callback=handle_error)
|
||||
else:
|
||||
@ -443,6 +446,9 @@ def mainloop_server(pool):
|
||||
global cable_list_state
|
||||
global scan_value
|
||||
global oldmode
|
||||
global arm_updates
|
||||
global animation_wait
|
||||
|
||||
if mode != oldmode:
|
||||
print(" ***** Running mode:", mode, "***** ")
|
||||
oldmode = mode
|
||||
@ -454,10 +460,16 @@ def mainloop_server(pool):
|
||||
|
||||
# do every loop!
|
||||
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)
|
||||
elif ring_animation is not None and real:
|
||||
ledsys.mainloop(led_set_mode, ring_animation)
|
||||
led_set_mode = None
|
||||
if animation_wait:
|
||||
if not arm_updates.empty():
|
||||
animation_wait = False
|
||||
val = arm_updates.get()
|
||||
ledsys.mainloop(led_set_mode, ring_animation)
|
||||
led_set_mode = None
|
||||
else:
|
||||
pass
|
||||
#fprint("Not triggering LED loop: no ring animation")
|
||||
@ -475,6 +487,7 @@ def mainloop_server(pool):
|
||||
fprint("Getting cable index " + str(counter) + " and scanning...")
|
||||
arm_state = "GET"
|
||||
ring_animation = counter
|
||||
animation_wait=True
|
||||
led_set_mode = "GrabA"
|
||||
#ur5_control.to_camera(arm, counter)
|
||||
#arm_ready = True
|
||||
|
@ -20,8 +20,8 @@ class Rob():
|
||||
robot = None
|
||||
#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
|
||||
armc = config["arm"]
|
||||
self.ip = armc["ip"]
|
||||
@ -33,6 +33,7 @@ class Rob():
|
||||
self.limb2 = limbs["limb2"]
|
||||
self.limb3 = limbs["limb3"]
|
||||
self.limb_wrist = limbs["limb_wrist"]
|
||||
self.pos_updates = pos_queue
|
||||
#self.init_arm()
|
||||
|
||||
def ping(host):
|
||||
|
Loading…
x
Reference in New Issue
Block a user