Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在OpenCV中绘制平面的法向量_Opencv_Image Processing_Camera_Linear Algebra_Pose Estimation - Fatal编程技术网

在OpenCV中绘制平面的法向量

在OpenCV中绘制平面的法向量,opencv,image-processing,camera,linear-algebra,pose-estimation,Opencv,Image Processing,Camera,Linear Algebra,Pose Estimation,我用二维条码来识别三维空间中的一个平面,我想画出它相对于中心的法线 这是我用来计算法线的代码 def compute_normal(camera, board, bounds, frame): extrinsics, ip, op = get_extrinsics(camera, frame, board, bounds) extrinsic = extrinsics[0] if not extrinsic: return [], None camera_tr

我用二维条码来识别三维空间中的一个平面,我想画出它相对于中心的法线

这是我用来计算法线的代码

def compute_normal(camera, board, bounds, frame):
    extrinsics, ip, op = get_extrinsics(camera, frame, board, bounds)
    extrinsic = extrinsics[0]

    if not extrinsic: return [], None

    camera_transform = M_from_extrinsic(extrinsic)
    transformed_board = transform_board(board, camera_transform)

    # change this to be the corners of any board, not just 4-square

    p1 = transformed_board[3][:3]
    p2 = transformed_board[6][:3]
    p3 = transformed_board[8][:3]

    l1 = p2 - p1
    l2 = p3 - p1

    normal = np.cross(l1, l2)

    return normal, extrinsic
board
仅仅是一个3xN的对象点数组(一切都由solvePnP支持)。点p1、p2、p3是理想校准板的左上角、右上角和左下角。圆圈点是我选择用于计算的点。其他几点是没有考虑到这个问题的更多角落

在我计算了法线之后,这就是我绘制它的方式

normal, extrinsic = compute_normal(camera0, board0, [[0, 4]], im)

if len(normal):

    projected_center, jac0 = cv2.projectPoints(board_center, extrinsic.rvec, extrinsic.tvec, camera0.mtx, camera0.dist)
    projected_norm, jac1 = cv2.projectPoints(np.array([normal]), extrinsic.rvec, extrinsic.tvec, camera0.mtx, camera0.dist)

    origin = clean_image_points(projected_center.reshape(1, 2))[0]
    vec = clean_image_points(projected_norm.reshape(1, 2))[0]

    cv2.arrowedLine(im, origin, vec, (0, 255, 0), 5)
然而,我得到的结果是这样的

如您所见,绿线指向某个应该指向屏幕的方向,因为电路板或多或少正面对着相机

我可以确认,由于我在其他几个地方使用它,因此计算外部变量的工作正常。我只是不确定正常的计算和绘图


谢谢你的帮助

这本身不是一个答案,但是您可以为自己的调试实时流化输出吗?你可能会注意到,当你右转时,箭头向左移动(x轴为负数),或者它似乎沿着对角线镜像(y和x值切换)。

是的,我想我很快会尝试一下。唯一的问题是它是一个4K的feed,而我的笔记本电脑没有那么快。试着通过2x pyrDown缩小尺寸,或者在imshow之前调整尺寸。交叉发布:。请每个社区都应该诚实地回答问题,而不浪费任何人的时间。