Last active
October 27, 2023 01:52
-
-
Save coder-ghw/63972a357d1a56566c1e6bc7270f8b8f to your computer and use it in GitHub Desktop.
python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
#%% | |
def generateData(n = 30): | |
# similar to peaks() function in MATLAB | |
g = np.linspace(-2.0, 2.0, n) | |
X, Y = np.meshgrid(g, g) | |
X, Y = X.reshape(-1,1), Y.reshape(-1,1) | |
#a, b, c, d , e = -5, -5, 1, 1, 10 | |
a, b, c, d , e = -1.29166667, -1.29166667, 0.41666667, 1.91666667, 135.77777778 | |
Z = a * X**2 + b* Y**2 +c*X+ d*Y + e + np.random.random(X.shape) | |
return X, Y, Z | |
X, Y, Z = generateData() | |
ax = plt.figure().add_subplot(projection='3d') | |
ax.scatter(X, Y, Z, c='r') | |
plt.xlabel('X') | |
plt.ylabel('Y') | |
ax.set_zlabel('Z') | |
ax.axis('equal') | |
ax.axis('tight') | |
plt.show() | |
# %% | |
ONES = np.ones((9,1)) | |
A = np.c_[X**2, Y**2, X, Y, ONES] | |
A_pinv = np.linalg.pinv(A) | |
# !!!代码中这里runtime calc | |
B = np.matmul(A_pinv, Z) | |
Z_new = np.matmul(A, B) | |
ax = plt.figure().add_subplot(projection='3d') | |
ax.scatter(X, Y, Z_new, c='g', s=5) | |
center_x = (-B[2]/(2*B[0])) | |
center_y = (-B[3]/(2*B[0])) | |
center_z = np.int32(B[0]*center_x**2 + B[1]*center_y**2 + B[2]*center_x+ B[3]*center_y + B[4]) | |
ax.scatter(center_x, center_y, center_z, c='r', s=20) | |
plt.xlabel('X') | |
plt.ylabel('Y') | |
ax.set_zlabel('Z') | |
ax.axis('tight') | |
plt.show() | |
B, (center_x, center_y, center_z) | |
#%% | |
np.set_printoptions(suppress=True) | |
data = A_pinv | |
data.reshape(-1, 1).flatten() | |
# %% | |
Z_0 = np.array([127, 130, 122, 134, 136, 128, 150, 154, 144]) | |
B_0 = np.matmul(A_pinv, Z_0) | |
ax = plt.figure().add_subplot(projection='3d') | |
ax.scatter(X, Y, Z_0, c='r') | |
plt.xlabel('X') | |
plt.ylabel('Y') | |
ax.set_zlabel('Z') | |
ax.axis('equal') | |
ax.axis('tight') | |
plt.show() | |
B_0, np.array(Z_0).reshape(-1, 3) | |
# %% | |
Z_1 = np.array([118, 127, 125, 130, 136, 131, 131, 134, 128]) | |
B_1 = np.matmul(A_pinv, Z_1) | |
ax = plt.figure().add_subplot(projection='3d') | |
ax.scatter(X, Y, Z_1, c='r') | |
plt.xlabel('X') | |
plt.ylabel('Y') | |
ax.set_zlabel('Z') | |
ax.axis('equal') | |
ax.axis('tight') | |
plt.show() | |
B_1, np.array(Z_1).reshape(-1, 3) | |
# %% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import os | |
import sys | |
import numpy as np | |
import matplotlib.pyplot as plt | |
import cv2 as cv | |
def parse_args(): | |
parser = argparse.ArgumentParser() | |
parser.add_argument("image", type=str, help="test image file") | |
parser.add_argument("file_in", type=str, help="test image file in") | |
parser.add_argument("file_exp", type=str, help="test result file") | |
parser.add_argument("--result_cv", type=str, help="test result file") | |
params = parser.parse_args() | |
return params | |
def main(args): | |
if __name__ == "__main__": | |
args = parse_args() | |
main(args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
# Lines | |
# 显示线的信息 | |
x = np.linspace(int(list(dspse[0].keys())[0]), int(list(dspse[-1].keys())[0]), 50) | |
p1, = plt.plot(x, mcs_old, color='r') | |
p2, = plt.plot(x, mcs, color='g') | |
plt.title('Compare: match counts') | |
plt.ylabel('Match counts') | |
plt.xlabel('Frame') | |
plt.legend([p1, p2], ['master','new'], loc='lower right') | |
#显示坐标点信息 | |
plt.annotate("text", xy=(10,10), xytext=(12,12), color='r') | |
## image 将图片拼接显示 | |
from PIL import Image | |
from IPython.display import display | |
image = Image.fromarray(np.column_stack([image0, image1])) | |
display(image) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment