JakubSochor / BoxCars

Source code related to BoxCars publication
205 stars 67 forks source link

Is it possible to derived the orientation from existing label? #1

Closed Zehaos closed 7 years ago

Zehaos commented 7 years ago

Hi, @JakubSochor, Is it possible to derived the orientation from existing label (camera intrinsics, vanishing points and so on)? Thank you~

JakubSochor commented 7 years ago

Hi, orientation of what? Camera or vehicle?

Zehaos commented 7 years ago

@JakubSochor, of the vehicle

JakubSochor commented 7 years ago

Yes, it is possible to compute the viewpoint vector to any point on the screen using following code.


def getFocal(vp1, vp2, pp):
    return math.sqrt(- np.dot(vp1[0:2]-pp[0:2], vp2[0:2]-pp[0:2]))

def getViewpoint(p, vp1, vp2, pp):
    try:
        focal = getFocal(vp1, vp2, pp)
    except ValueError:
        return None    
    vp1W = np.concatenate((vp1[0:2]-pp[0:2], [focal]))
    vp2W = np.concatenate((vp2[0:2]-pp[0:2], [focal]))
    if vp1[0] < vp2[0]:
        vp2W = -vp2W
    vp3W = np.cross(vp1W, vp2W)
    vp1W, vp2W, vp3W = tuple(map(lambda u: u/np.linalg.norm(u), [vp1W, vp2W, vp3W]))
    pW = np.concatenate((p[0:2]-pp[0:2], [focal]))
    pW = pW/np.linalg.norm(pW)
    viewPoint = -np.dot(np.array([vp1W, vp2W, vp3W]), pW)
    return viewPoint

To compute the viewpoint to the vehicle, you can use center of the 3D bounding box. The center can be obtained as intersection of diagonals of the 3D bounding box.

Zehaos commented 7 years ago

@JakubSochor, It is seem that function below need a point from the original image. def getViewpoint(p, vp1, vp2, pp): The problem is that the given images only contains part(car region) of the original, and the 3DBB's coordinate is related to this region, such we can not calculate the center of the 3DBB on the original image. Do I make myself clear?

JakubSochor commented 7 years ago

The 3DBB coordinates are in the original image space. To convert them to the cropped image space you need to subtract the 3DBB_offset. Therefore, you can just use the 3DBB in the original image space to compute the center of the vehicle.

Zehaos commented 7 years ago

Got it, thank you very much : )

hanlanqian commented 2 years ago

@Zehaos Hi! The orientation you get is the center point of 3Dbox corresponding to the origin of the World Coordinate System, Right? But What should I do if I want to get the real front orientation of the vehicle? Can you please guide me on how to deal with it? Thanks~