Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cv2
- import numpy as np
- import onnxruntime as rt
- from skimage.transform import resize
- if __name__ == "__main__":
- sess = rt.InferenceSession('model.onnx')
- shape = sess.get_inputs()[0].shape
- output = sess.get_outputs()[0].shape
- shape.pop(0)
- shape = tuple(shape)
- output.pop(0)
- img = cv2.imread('bill.jpg')
- X = np.array(img)
- X = resize(X/255, shape)
- X = X[np.newaxis, :, :, :]
- X = X.astype(np.float32)
- input_name = sess.get_inputs()[0].name
- label_name = sess.get_outputs()[0].name
- pred_onnx = sess.run([label_name], {input_name: X})
- print(pred_onnx)
- while True:
- gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
- for x, y, w, h in pred_onnx:
- cv2.rectangle(img, (x, y), (x+w, y+h), (0, 255, 0), 2)
- roiGray = gray[y:y+h, x:x+w]
- roiColor = img[y:y+h, x:x+w]
- cv2.imshow("Detect", cv2.resize(img, (500, 500)))
- cv2.waitKey(0)
Advertisement
Add Comment
Please, Sign In to add comment