如何使我的计算速度更快?从txt文件追加时出现问题?

2024-06-26 11:07:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个txt文件,它有

x1,y1,z1,w1,desc1
x2,y2,z2,w2,desc2
till
xn,yn,zn,wn,descn

x、y、z和w是浮点数 desc是61个浮点数(不是数组或列表!图片中的图形仅用于说明)

我需要在图片中应用下面提到的等式 Need to apply the equation and have the output (u1 and v1 correspondence to desc1)

我的代码是

for i in range(len(Xsnew)):
            #Xsnew is all the x's in the txt file
            x_features = Xsnew[i]
            y_features = Ysnew[i]
            z_features = Zsnew[i]
            #print("x_features", x_features)
            # Feature coordinates is the 3x1 matrix x1 y1 z1 in the picture
            feature_coordinates = np.array([[x_features],[y_features],[z_features],[1]], dtype=float)
            # P in the picture is the projection matrix 
            position_of_features = np.dot(projection_matrix, feature_coordinates)
            u, v, w = position_of_features[0], position_of_features[1], position_of_features[2]
            u_normalized = u / w
            v_normalized = v / w
            #print("U normalized is {} and V normalized is {}". format(u_normalized,v_normalized))
            virtual_camera_desc = desc_features[i]
            #print("virtual_camera_desc", virtual_camera_desc)

            #print(" u = {} and v = {} and X_features = {} and desc = {}". format(u_normalized,v_normalized,x_features,virtual_camera_desc))
            if 0 < u_normalized < image_height and 0 < v_normalized < image_width:
                #print(len(desc), len(virtual_camera_desc))
                #print("I SEE FEATURES")
                bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck= True)
                matches = bf.match(desc, virtual_camera_desc)

这很好,但速度太慢了。 我需要更快的算法,我在想怎么做“活”。但不确定,如何开始?有什么建议吗

谢谢:)


Tags: andoftheinlenisvirtualposition