Loads an image into the camera panel.
Displays the specified image in the camera interface.
planetcnc.image_to_cam(image)
#! /usr/bin/env python import planetcnc # Assuming 'img' is a valid image capsule object success = planetcnc.image_to_cam(img) print("Image loaded into camera panel:", success)
#! /usr/bin/env python import planetcnc from PIL import Image # Open an image img_p = Image.open(planetcnc.get_path_profile("cat.png")) width, height = img_p.size channels = len(img_p.getbands()) data = img_p.tobytes() # Open the image using the PlanetCNC SDK img = planetcnc.image_open_data(data, width, height, channels, True, True) if img: print("Image successfully opened") # Send image to camera panel if planetcnc.image_to_cam(img): print("Image successfully sent to camera panel") else: print("Failed to send image to camera panel") # Close the image planetcnc.image_close(img) else: print("Failed to open image")
#! /usr/bin/env python import planetcnc from PIL import Image # Open an image img_p = Image.open(planetcnc.get_path_profile("cat.png")) width, height = img_p.size channels = len(img_p.getbands()) data = bytearray(img_p.tobytes()) # Open the image using the PlanetCNC SDK img = planetcnc.image_open_data(data, width, height, channels, True, True) if img: print("Image successfully opened") # Send image to camera panel if planetcnc.image_to_cam(img): print("Image successfully sent to camera panel") else: print("Failed to send image to camera panel") # Close the image planetcnc.image_close(img) else: print("Failed to open image")
#! /usr/bin/env python import planetcnc from PIL import Image import numpy as np # Open an image img_p = Image.open(planetcnc.get_path_profile("cat.png")).convert("RGB") # Create NumPy Array data = np.array(img_p) # Open the image using the PlanetCNC SDK img = planetcnc.image_open_data(data, True, True) if img: print("Image successfully opened") # Send image to camera panel if planetcnc.image_to_cam(img): print("Image successfully sent to camera panel") else: print("Failed to send image to camera panel") # Close the image planetcnc.image_close(img) else: print("Failed to open image")
#! /usr/bin/env python import planetcnc from PIL import Image import numpy as np # Open an image img_p = Image.open(planetcnc.get_path_profile("cat.png")).convert("RGB") # Create NumPy Array data = np.array(img_p) data_bgr = np.ascontiguousarray(data[..., ::-1]) # Open the image using the PlanetCNC SDK img = planetcnc.image_open_data(data_bgr, True, False) if img: print("Image successfully opened") # Send image to camera panel if planetcnc.image_to_cam(img): print("Image successfully sent to camera panel") else: print("Failed to send image to camera panel") # Close the image planetcnc.image_close(img) else: print("Failed to open image")
#! /usr/bin/env python import cv2 import planetcnc # Open an image using OpenCV img_cv = cv2.imread(planetcnc.get_path_profile("cat.png"), cv2.IMREAD_COLOR) height, width, channels = img_cv.shape data = img_cv.tobytes() # Open the image using the PlanetCNC SDK img = planetcnc.image_open_data(data, width, height, channels, False) if img: print("Image successfully opened") # Send image to camera panel if planetcnc.image_to_cam(img): print("Image successfully sent to camera panel") else: print("Failed to send image to camera panel") # Close the image planetcnc.image_close(img) else: print("Failed to open image")
#! /usr/bin/env python import time import cv2 import planetcnc def OpenCV(): print("OpenCV START") count = 0 # Open PlanetCNC camera window id = planetcnc.cmd_get_id("Machine.Camera.Show") if not planetcnc.cmd_exec(id, 10000): print("Failed to camera window") return # Open video device cap = cv2.VideoCapture(0, cv2.CAP_DSHOW) #Windows #cap = cv2.VideoCapture(0, cv2.CAP_V4L2) #Linux #cap.set(cv2.CAP_PROP_FPS, 30) #cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640) #cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480) while(1): # Capture frame ret, frame = cap.read() if not ret: print("Error: Could not capture frame") break # Convert frame to PlanetCNC Image img = planetcnc.image_open_data(frame, True) if not img: print("Failed to open image") break # Send image to PlaneCNC if not planetcnc.image_to_cam(img): planetcnc.image_close(img) print("Failed to send image to camera panel") break # Close the image planetcnc.image_close(img) #time.sleep(0.1) msg = {} if planetcnc.read_message(msg): print("Received ", msg) if msg["OpenCV"] == 0: print("Received EXIT message") break count += 1 if (count % 10) == 0: print(f"Count: {count}") if (count >= 100): break cap.release() cv2.destroyAllWindows() print("OpenCV END") # Run function OpenCV()