Код: Выделить всё
# Initialize the inference pipeline
pipeline = InferencePipeline.init(
model_id="crap-object-detection/1",
api_key="VCkdCb9yChgHCrexOwvX",
video_reference=0,
on_prediction=my_custom_sink,
)
Это мой скрипт, который обрезает видеопоток. Как вы можете видеть, он отображает изображение с камеры и результирующее видео — boardImg. Я хотел бы использовать boardImg в качестве video_reference в приведенном выше коде.
Однако video_reference принимает только путь к видео, идентификатор устройства или URL-адрес потока RTSP. Как я могу это сделать? Спасибо.
Код: Выделить всё
import cv2
import os
import time
import numpy as np
from Cropping import ExtractAndStraightenFromImage
from LocateGrid import DetectGrid
IMAGE_FILE_PATH = os.path.join("Capture", "BoardPictures")
# Create directory to save pictures if it doesn't exist
if not os.path.exists(IMAGE_FILE_PATH):
os.makedirs(IMAGE_FILE_PATH)
# Start the video capture
vid = cv2.VideoCapture(0) # ID 1 assumes a second camera (like your Orbbec Astra). Use 0 for default camera
is_automatic = False
def apply_morphological_ops(img):
# Define a kernel size
kernel = np.ones((5,5),np.uint8)
# Apply morphological opening
opening = cv2.morphologyEx(img, cv2.MORPH_OPEN, kernel)
return opening
try:
while True:
ret, frame = vid.read()
if not ret:
print("Failed to grab frame")
break
key = cv2.waitKey(1)
if key == 32: # Spacebar pressed
unique_filename = time.strftime("%Y%m%d_%H%M%S") + ".png" # Unique filename using current timestamp
screenshot_path = os.path.join(IMAGE_FILE_PATH, unique_filename)
boardImg = ExtractAndStraightenFromImage(frame)
cv2.imwrite(screenshot_path, boardImg) # Save the screenshot
print(f"Screenshot saved as {screenshot_path}")
boardImg = ExtractAndStraightenFromImage(frame)
#checkBoard = DetectGrid(boardImg)
#checkBoard2 = apply_morphological_ops(checkBoard)
cv2.imshow("Frame", frame)
#cv2.imshow("Checkboard filter", checkBoard2)
cv2.imshow("Board img", boardImg)
#cv2.imshow("Check board", checkBoard)
finally:
vid.release()
cv2.destroyAllWindows()
Источник: https://stackoverflow.com/questions/781 ... erence-pip