Pos Indonesia

Lacak Kiriman

POS INDONESIA
Kirim Barang Tanpa Khawatir
import cv2 import pyvirtualcam from pyvirtualcam import PixelFormat import numpy as np import os import time # ========================================================== # KONFIGURASI FHD+ (1080 x 2340) - RASIO 19.5:9 # ========================================================== FOLDER_FOTO = r'C:\Picture' WIDTH_SAFE = 1080 HEIGHT_SAFE = 2340 FPS_TARGET = 30 list_gambar = [f for f in os.listdir(FOLDER_FOTO) if f.lower().endswith(('.png', '.jpg', '.jpeg'))] params = { "Pilih_Gambar": 0, "Skala_Foto": 100, "Geser_X": 50, "Geser_Y": 50, "Lebar_Oval": 650, # Memanjang ke samping "Tinggi_Oval": 400, # Pipih ke atas-bawah "Pencahayaan": 100, "Flip_Horisontal": 0, "Flip_Vertikal": 0, "Mode_KTP": 0 } def nothing(x): pass def mouse_click_control(event, x, y, flags, param): if event == cv2.EVENT_LBUTTONDOWN: for i, key in enumerate(params.keys()): y_start = 10 + (i * 45) y_end = y_start + 35 step = 1 if "Flip" in key or key in ["Pilih_Gambar", "Mode_KTP"] else 5 if 180 <= x <= 230 and y_start <= y <= y_end: params[key] = max(0, params[key] - step) cv2.setTrackbarPos(key, "Setting_Kamera", params[key]) elif 240 <= x <= 280 and y_start <= y <= y_end: params[key] = params[key] + step cv2.setTrackbarPos(key, "Setting_Kamera", params[key]) def main(): if not list_gambar: return cv2.namedWindow("Preview System", cv2.WINDOW_NORMAL) cv2.resizeWindow("Preview System", 415, 900) cv2.namedWindow("Control Panel", cv2.WINDOW_AUTOSIZE) cv2.setMouseCallback("Control Panel", mouse_click_control) cv2.namedWindow("Setting_Kamera", cv2.WINDOW_AUTOSIZE) for label, val in params.items(): max_v = 1 if "Flip" in label or label == "Mode_KTP" else (len(list_gambar)-1 if label == "Pilih_Gambar" else 1500) cv2.createTrackbar(label, "Setting_Kamera", val, max_v, nothing) current_idx = -1 img_master = None try: with pyvirtualcam.Camera(width=WIDTH_SAFE, height=HEIGHT_SAFE, fps=FPS_TARGET, fmt=PixelFormat.RGB) as cam: while True: start_time = time.time() for k in params.keys(): params[k] = cv2.getTrackbarPos(k, "Setting_Kamera") if params["Pilih_Gambar"] != current_idx: current_idx = params["Pilih_Gambar"] raw = cv2.imread(os.path.join(FOLDER_FOTO, list_gambar[current_idx])) if raw is not None: # Tetap Horizontal (4000x1846) img_master = cv2.resize(raw, (4000, 1846), interpolation=cv2.INTER_LANCZOS4) else: continue img_temp = img_master.copy() if params["Flip_Horisontal"] == 1: img_temp = cv2.flip(img_temp, 1) skala = max(0.1, params["Skala_Foto"] / 100.0) new_w, new_h = int(img_temp.shape[1] * skala), int(img_temp.shape[0] * skala) resized = cv2.resize(img_temp, (new_w, new_h), interpolation=cv2.INTER_LANCZOS4) canvas = np.ones((HEIGHT_SAFE, WIDTH_SAFE, 3), dtype=np.uint8) * 255 off_x = int((WIDTH_SAFE - new_w) * (params["Geser_X"]/100.0)) off_y = int((HEIGHT_SAFE - new_h) * (params["Geser_Y"]/100.0)) x1, x2 = max(0, off_x), min(WIDTH_SAFE, off_x + new_w) y1, y2 = max(0, off_y), min(HEIGHT_SAFE, off_y + new_h) img_x1, img_x2 = max(0, -off_x), min(new_w, WIDTH_SAFE - off_x) img_y1, img_y2 = max(0, -off_y), min(new_h, HEIGHT_SAFE - off_y) if x1 < x2 and y1 < y2: canvas[y1:y2, x1:x2] = resized[img_y1:img_y2, img_x1:img_x2] canvas = cv2.convertScaleAbs(canvas, alpha=params["Pencahayaan"]/100.0, beta=0) if params["Mode_KTP"] == 0: mask = np.zeros((HEIGHT_SAFE, WIDTH_SAFE), dtype=np.uint8) cv2.ellipse(mask, (WIDTH_SAFE//2, HEIGHT_SAFE//2), (params["Lebar_Oval"], params["Tinggi_Oval"]), 0, 0, 360, 255, -1) mask_smooth = cv2.GaussianBlur(mask, (85, 85), 0) alpha = cv2.cvtColor(mask_smooth, cv2.COLOR_GRAY2BGR).astype(float) / 255.0 final_output = (canvas.astype(float) * alpha + 255 * (1 - alpha)).astype(np.uint8) else: final_output = canvas # --- MENGEMBALIKAN UI PANEL YANG HILANG --- panel = np.ones((520, 320, 3), dtype=np.uint8) * 230 for i, (l, v) in enumerate(params.items()): y = 10 + (i * 45) cv2.putText(panel, f"{l[:11]}: {v}", (10, y+25), 1, 0.8, (0,0,0), 1) cv2.rectangle(panel, (180, y), (230, y+35), (170,170,170), -1) cv2.rectangle(panel, (250, y), (300, y+35), (170,170,170), -1) cv2.putText(panel, "-", (198, y+26), 1, 1.5, (0,0,250), 2) cv2.putText(panel, "+", (265, y+26), 1, 1.5, (0,150,0), 2) cv2.imshow("Control Panel", panel) cv2.imshow("Preview System", final_output) cam.send(np.ascontiguousarray(cv2.cvtColor(final_output, cv2.COLOR_BGR2RGB))) if cv2.waitKey(1) & 0xFF == ord('q'): break time.sleep(max(1/FPS_TARGET - (time.time() - start_time), 0.001)) except Exception as e: print(f"Error: {e}") finally: cv2.destroyAllWindows() if __name__ == "__main__": main()
Tombol Kembali Pos Indonesia KEMBALI