我想在 OpenCV feed 上叠加 3d 对象。我在这里找到了一个例子,它使用网络摄像头视频作为 OpenGL 中的纹理。我改变了一些部分,以便它可以与 cv2 一起使用。现在输出有点奇怪
代码
import cv2
from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
import numpy as np
import sys
#window dimensions
width = 1280
height = 720
nRange = 1.0
global capture
capture = None
def cv2array(im):
h,w,c=im.shape
a = np.fromstring(
im.tostring(),
dtype=im.dtype,
count=w*h*c)
a.shape = (h,w,c)
return a
def init():
#glclearcolor (r, g, b, alpha)
glClearColor(0.0, 0.0, 0.0, 1.0)
glutDisplayFunc(display)
glutReshapeFunc(reshape)
glutKeyboardFunc(keyboard)
glutIdleFunc(idle)
def idle(): …Run Code Online (Sandbox Code Playgroud)