|
import cv2
import yaml
import numpy as np
import sys
import os
def test():
camera_files = "./yaml/camera.yaml"
W, H = 1280, 720
init_files="./yaml/init.yaml"
with open(init_files, "r") as f:
init_data = yaml.load(f)
source = init_data["source"]
cap = cv2.VideoCapture(source[0])
cap.set(3, W)
cap.set(4, H)
with open(camera_files, "r") as f:
data = yaml.load(f)
K = np.array(data["K"])
D = np.array(data["D"])
map1, map2 = cv2.fisheye.initUndistortRectifyMap(
K,
D,
np.eye(3),
K,
(W, H),
cv2.CV_16SC2
)
while True:
ret, frame = cap.read()
#frame=cv2.resize(frame,(640,480))
#frame = cv2.remap(frame, map1, map2, interpolation=cv2.INTER_LINEAR, borderMode=cv2.BORDER_CONSTANT)
cv2.imshow("capture", frame)
if cv2.waitKey(10) & 0xFF == ord('q'):
img = frame
cv2.imwrite('img.jpg', frame) # 存储为图像
break
cap.release()
cv2.destroyAllWindows()
#img = cv2.imread('img.jpg')
def on_EVENT_LBUTTONDOWN(event, x, y, flags, param):
if event == cv2.EVENT_LBUTTONDOWN:
xy = "%d,%d" % (x, y)
cv2.circle(img, (x, y), 1, (255, 0, 0), thickness=-1)
print((x,y))
cv2.putText(img, xy, (x, y), cv2.FONT_HERSHEY_PLAIN,
1.5, (255, 255, 255), thickness=2)
cv2.imshow("image", img)
cv2.namedWindow("image", cv2.WINDOW_AUTOSIZE)
cv2.setMouseCallback("image", on_EVENT_LBUTTONDOWN)
cv2.imshow("image", img)
while (True):
try:
if cv2.waitKey(10) & 0xFF == ord('q'):
break
except Exception:
cv2.destroyWindow("image")
break
if __name__=='__main__':
test()
|
|
共 16 个关于本帖的回复 最后回复于 2024-4-24 14:49