|
import cv2 as cv |
|
import numpy as np |
|
|
|
|
|
input_video = r'data/araba.mp4' |
|
output_video = r'data/araba_output.mp4' |
|
|
|
|
|
cap = cv.VideoCapture(input_video) |
|
|
|
|
|
fourcc = cv.VideoWriter_fourcc(*'mp4v') |
|
fps = int(cap.get(cv.CAP_PROP_FPS)) |
|
width = int(cap.get(cv.CAP_PROP_FRAME_WIDTH)) |
|
height = int(cap.get(cv.CAP_PROP_FRAME_HEIGHT)) |
|
|
|
out = cv.VideoWriter(output_video, fourcc, fps, (width, height)) |
|
|
|
|
|
cuda_enabled = cv.cuda.getCudaEnabledDeviceCount() > 0 |
|
device_label = "Device: GPU" if cuda_enabled else "Device: CPU" |
|
|
|
|
|
delay = int(1000 / fps) |
|
|
|
while cap.isOpened(): |
|
ret, frame = cap.read() |
|
|
|
if not ret: |
|
break |
|
|
|
|
|
b, g, r = cv.split(frame) |
|
|
|
rgb_frame = cv.merge((b, r, r)) |
|
|
|
|
|
cv.putText(rgb_frame, device_label, (10, 30), cv.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2, cv.LINE_AA) |
|
|
|
cv.imshow('Mavi video', rgb_frame) |
|
|
|
out.write(rgb_frame) |
|
|
|
|
|
if cv.waitKey(delay) & 0xFF == ord('q'): |
|
break |
|
|
|
cap.release() |
|
out.release() |
|
cv.destroyAllWindows() |