File size: 1,765 Bytes
07ad80f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
import cv2 as cv
import argparse
from dexined import Dexined
def get_args_parser(func_args):
parser = argparse.ArgumentParser(add_help=False)
parser.add_argument('--input', help='Path to input image or video file. Skip this argument to capture frames from a camera.', default=0, required=False)
parser.add_argument('--model', help='Path to dexined.onnx', default='edge_detection_dexined_2024sep.onnx', required=False)
args, _ = parser.parse_known_args()
parser = argparse.ArgumentParser(parents=[parser],
description='', formatter_class=argparse.RawTextHelpFormatter)
return parser.parse_args(func_args)
def main(func_args=None):
args = get_args_parser(func_args)
dexined = Dexined(modelPath=args.model)
# Open video or capture from camera
cap = cv.VideoCapture(cv.samples.findFile(args.input) if args.input else 0)
if not cap.isOpened():
print("Failed to open the input video")
exit(-1)
cv.namedWindow('Input', cv.WINDOW_AUTOSIZE)
cv.namedWindow('Output', cv.WINDOW_AUTOSIZE)
cv.moveWindow('Output', 200, 50)
# Process frames
tm = cv.TickMeter()
while cv.waitKey(1) < 0:
hasFrame, image = cap.read()
if not hasFrame:
print("Press any key to exit")
cv.waitKey(0)
break
tm.start()
result = dexined.infer(image)
tm.stop()
label = 'Inference time: {:.2f} ms, FPS: {:.2f}'.format(tm.getTimeMilli(), tm.getFPS())
cv.imshow("Input", image)
cv.putText(result, label, (0, 15), cv.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255))
cv.imshow("Output", result)
cv.destroyAllWindows()
if __name__ == '__main__':
main()
|