妈的,这么看,我一点点代码操守都没有!!!!
垃圾程序○
C++版本
import cv2
import numpy as np
def read_map(filepath):
f = open(filepath)
map = np.fromfile(f, dtype=np.float32)
return map
maxpx_ = ".../robot/mapx"
maxpy_ = ".../robot/mapy"
mapx = read_map(maxpx_)
mapx = np.reshape(mapx, (720, 1280))
mapy = read_map(maxpy_)
mapy = np.reshape(mapy, (720, 1280))
#获得去除畸变的图像
def calibration(img):
mtx = np.array([ [ 2.43714600e+02, 0., 3.56074585e+02],
[0., 1.43695648e+02, 2.82849579e+02],
[0, 0, 1]])
dist = np.array([ 1.68765223e-01, 6.45689249e-01, -3.87637527e-07,
1.74045555e-05, 1.51894258e-02, 6.05511725e-01, 1.86023712e-01,
8.58336240e-02]).reshape((1,8))
mapx_cali ,mapy_cali = cv2.initUndistortRectifyMap(mtx, dist, None, mtx,(1280, 960), 5)
cali_img = cv2.remap(img, mapx_cali, mapy_cali, cv2.INTER_LINEAR)
return cali_img
params = cv2.SimpleBlobDetector_Params()
params.blobColor = 255
detector = cv2.SimpleBlobDetector_create(params)
lds_re_map = np.zeros((1280, 960, 1), dtype=np.uint8) # 用于显示的类别地图
cv2.circle(lds_re_map,(360,360),15,(255,255,255),-1)
cv2.circle(lds_re_map,(760,360),15,(255,213,255),-1)
cv2.circle(lds_re_map,(760,760),15,(255,213,255),-1)
cv2.circle(lds_re_map,(460,760),15,(255,255,255),-1)
cali_img = calibration(lds_re_map)
print(mapx[1])
img2 = cv2.remap(lds_re_map, mapx, mapy, cv2.INTER_LINEAR)
keypoints = detector.detect(img2)
keypoints2 = detector.detect(cali_img)
cv2.imshow("lds_re_map", lds_re_map)
cv2.waitKey(0)
cv2.imshow("cali_img", cali_img)
cv2.waitKey(0)
points_met_1=[]
for key_p in keypoints:
# points_met_1.append([key_p.pt[0],key_p.pt[1] ])
points_met_1.append([[key_p.pt[0], key_p.pt[1] ]])
points_met_2 = []
for key_p in keypoints2:
# points_met_2.append([key_p.pt[0],key_p.pt[1] ])
points_met_2.append([[key_p.pt[0], key_p.pt[1] ] ])
H, _ = cv2.findHomography(np
```javascript.array(points_met_1), np.array(points_met_2) )
print(H)
kpt_image = cv2.drawKeypoints(img2, keypoints, np.array([]),(0,0,255),cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
cv2.imshow("Keypoints", kpt_image)
cv2.waitKey(0)
cv2.destroyAllWindows()
Python 版本
import cv2
import numpy as np
def read_map(filepath):
f = open(filepath)
map = np.fromfile(f, dtype=np.float32)
return map
robot_id = 187
maxpx_ = "/media/crystal/crystal/ai_map_data/robot" + str(robot_id) + "/mapx"
maxpy_ = "/media/crystal/crystal/ai_map_data/robot" + str(robot_id) + "/mapy"
mapx = read_map(maxpx_)
mapx = np.reshape(mapx, (720, 1280))
mapy = read_map(maxpy_)
mapy = np.reshape(mapy, (720, 1280))
def calibration(img):
mtx = np.array([ [ 3.43714600e+02, 0., 6.56074585e+02],
[0., 3.43695648e+02, 4.82849579e+02],
[0, 0, 1]])
dist = np.array([ 5.68765223e-01, 6.45689249e-01, -3.87637527e-07,
4.74045555e-05, 2.51894258e-02, 6.05511725e-01, 6.86023712e-01,
8.58336240e-02]).reshape((1,8))
mapx_cali ,mapy_cali = cv2.initUndistortRectifyMap(mtx, dist, None, mtx,(1280, 960), 5)
cali_img = cv2.remap(img, mapx_cali, mapy_cali, cv2.INTER_LINEAR)
return cali_img
params = cv2.SimpleBlobDetector_Params()
params.blobColor = 255
detector = cv2.SimpleBlobDetector_create(params)
lds_re_map = np.zeros((1280, 960, 1), dtype=np.uint8) # 用于显示的类别地图
cv2.circle(lds_re_map,(360,360),15,(255,255,255),-1)
cv2.circle(lds_re_map,(760,360),15,(255,213,255),-1)
cv2.circle(lds_re_map,(760,760),15,(255,213,255),-1)
cv2.circle(lds_re_map,(460,760),15,(255,255,255),-1)
# 找到cali 到Img2的代码
cali_img = calibration(lds_re_map)
print(mapx[1])
img2 = cv2.remap(lds_re_map, mapx, mapy, cv2.INTER_LINEAR)
keypoints = detector.detect(img2)
keypoints2 = detector.detect(cali_img)
cv2.imshow("lds_re_map", lds_re_map)
cv2.waitKey(0)
cv2.imshow("cali_img", cali_img)
cv2.waitKey(0)
points_met_1=[]
for key_p in keypoints:
# points_met_1.append([key_p.pt[0],key_p.pt[1] ])
points_met_1.append([[key_p.pt[0], key_p.pt[1] ]])
points_met_2 = []
for key_p in keypoints2:
# points_met_2.append([key_p.pt[0],key_p.pt[1] ])
points_met_2.append([[key_p.pt[0], key_p.pt[1] ] ])
H, _ = cv2.findHomography(np.array(points_met_1), np.array(points_met_2) )
print(H)
# print("keypoints ", len(img2 ))
kpt_image = cv2.drawKeypoints(img2, keypoints, np.array([]),(0,0,255),cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
cv2.imshow("Keypoints", kpt_image)
cv2.waitKey(0)
cv2.destroyAllWindows()