Render object in world via webcam

I am new to game development and panda3d. I want to render object in real world by opening webcam
in realtime. I tried to open webcam following this discussion. But unable to figure out how to render object in live webcam feed. If someone guides me through the steps i need to look for will be very helpful.

This works for me, although you might not need OpenCV like I do:

import cv2
import panda3d
from direct.showbase.ShowBase import ShowBase
panda3d.core.load_prc_file_data("", "show-frame-rate-meter #t")
panda3d.core.load_prc_file_data("", "sync-video #f")

base = ShowBase()

# generate a frame geometry to apply the camera texture to
cardmaker = panda3d.core.CardMaker("frame")
frame = panda3d.core.NodePath(cardmaker.generate())
frame.flatten_light() # apply scale

cv_camera = cv2.VideoCapture(0 + cv2.CAP_DSHOW)
cv_camera_frame_texture = panda3d.core.Texture()
cv_camera_frame_texture.setup_2d_texture(640, 480, panda3d.core.Texture.T_unsigned_byte, panda3d.core.Texture.F_rgb8)
frame.set_texture(cv_camera_frame_texture, 1)

def update_usb_camera_frame(task):
	success_state, image =
	image = cv2.flip(image, 1)
	return task.again
base.task_mgr.do_method_later(1000/60*0.001, update_usb_camera_frame, "update_usb_camera_frame")

Thanks @bodaf62109 for the code.
Can you please provide code for rendering and 3D object in live cam.

With all due respect, that’s something you should learn from the documentation and do on your own.
If you have a specific question on how to do it on the way, please ask, but “please provide code for rendering and 3D object” is in the “please write the Panda3D code for me” territory.
OpenCV is not part of Panda3D and making them work together is a bit of an advanced topic, but your last question isn’t:

1 Like