def openglDrawOnScreenDetection(self, detection, cubeModel, camera): # Invert OpenGL's (implicit) viewport matrix and set it as the # projection matrix to allow drawing directly onto the screen in units # of pixels. # Note: The viewport matrix has been set previously using: # glViewport(0, 0, fbs_x, fbs_y); proj = np.linalg.inv(viewPortMatrix(camera.framebufferSize)) self.openglScene.flatProgram.setUniformMat4('proj', proj) # print 'proj', proj # Draw an axis-aligned cube scaled to the size of the detection: cubeModel.pos = np.array([detection.trans.x, detection.trans.y, 0]) cubeModel.dir = np.array([1, 0, 0]) cubeModel.up = np.array([0, 0, 1]) cubeModel.scale = np.array([detection.size[0], detection.size[1], 0.1]) # p = camera.P*np.mat([0,0,0, 1]).T # print 'mul', p # p = p/p[2] # print 'div', p # p = camera.project(np.mat([0,0,0, 1]).T) # cubeModel.pos = np.array([p[0], p[1], 0]) # cubeModel.scale = np.array([5, 5, 0.1]) cubeModel.draw(self.openglScene.flatProgram) # Reset the projection matrix to the camera's projection matrix: proj = camera.getOpenGlCameraMatrix() self.openglScene.flatProgram.setUniformMat4('proj', proj)
def getGroundProjectedDetection(self, detection, camera): dc = np.array([detection.trans.x, detection.trans.y, 0], np.float32) dhw = np.array([detection.size[0]*0.5, 0, 0]) dhh = np.array([0, detection.size[1]*0.5, 0]) vertices = [ dc - dhw + dhh, dc + dhw + dhh, dc + dhw - dhh, dc - dhw - dhh ] vpInv = np.linalg.inv(viewPortMatrix(camera.framebufferSize)) def unvp(u): x = vpInv*np.row_stack([np.mat(u).T, [1]]) x = x[:3] # return np.array(x.T) return np.array([x[0,0], x[1,0], x[2,0]]) vertices = [unvp(v) for v in vertices] gpverts = [camera.projectPointToGround(v) for v in vertices] return gpverts