Python Forum
How to receive webcam capture on spout?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to receive webcam capture on spout?
#1
I'm trying to let Spout receive a webcam capture done with OpenCV but I keep getting errors. How can I approach this problem in the best way?

Error:
C:\Users\User\Desktop\Spout-for-Python-master2\venv\Scripts\python.exe C:/Users/User/Desktop/Spout-for-Python-master2/spout_webcam_sender_example.py pygame 2.1.2 (SDL 2.0.18, Python 3.6.0) Hello from the pygame community. https://www.pygame.org/contribute.html Traceback (most recent call last): File "C:/Users/User/Desktop/Spout-for-Python-master2/spout_webcam_sender_example.py", line 125, in <module> main() File "C:/Users/User/Desktop/Spout-for-Python-master2/spout_webcam_sender_example.py", line 94, in main spoutSender.SendTexture(senderTextureID, GL_TEXTURE_2D, spoutSenderWidth, spoutSenderHeight, False, 0) Boost.Python.ArgumentError: Python argument types in SpoutSender.SendTexture(SpoutSender, numpy.uintc, IntConstant, int, int, bool, int) did not match C++ signature: SendTexture(class SpoutSender {lvalue}, unsigned int, unsigned int, unsigned int, unsigned int, bool, unsigned int) [ WARN:[email protected]] global D:\a\opencv-python\opencv-python\opencv\modules\videoio\src\cap_msmf.cpp (539) `anonymous-namespace'::SourceReaderCB::~SourceReaderCB terminating async callback
Code:
import sys
import os

sys.path.append('{}/Library/3{}'.format(os.getcwd(), sys.version_info[1]))

import argparse
import cv2
import SpoutSDK
import pygame
from pygame.locals import *
from OpenGL.GL import *
from OpenGL.GLU import *

"""parsing and configuration"""
def parse_args():
    desc = "Spout for Python webcam sender example"
    parser = argparse.ArgumentParser(description=desc)

    parser.add_argument('--camSize', nargs = 2, type=int, default=[640, 480], help='File path of content image (notation in the paper : x)')

    parser.add_argument('--camID', type=int, default=1, help='Webcam Device ID)')

    return parser.parse_args()


"""main"""
def main():

    # parse arguments
    args = parse_args()

    # window details
    width = args.camSize[0]
    height = args.camSize[1]
    display = (width,height)

    # window setup
    pygame.init()
    pygame.display.set_caption('Webcam')
    pygame.display.set_mode(display, DOUBLEBUF|OPENGL)
    pygame.display.gl_set_attribute(pygame.GL_ALPHA_SIZE, 8)

    # init capture & set size
    #cap = cv2.VideoCapture(args.camID)
    cap = cv2.VideoCapture(0)
    cap.set(3, width)
    cap.set(4, height)

    # OpenGL init
    glMatrixMode(GL_PROJECTION)
    glOrtho(0,width,height,0,1,-1)
    glMatrixMode(GL_MODELVIEW)
    glLoadIdentity()
    glDisable(GL_DEPTH_TEST)
    glClearColor(0.0,0.0,0.0,0.0)
    glEnable(GL_TEXTURE_2D)

    # init spout sender
    spoutSender = SpoutSDK.SpoutSender()
    spoutSenderWidth = width
    spoutSenderHeight = height
    # Its signature in c++ looks like this: bool CreateSender(const char *Sendername, unsigned int width, unsigned int height, DWORD dwFormat = 0);
    spoutSender.CreateSender('Spout for Python Webcam Sender Example', width, height, 0)

    # create texture id for use with Spout
    senderTextureID = glGenTextures(1)

    # initalise our sender texture
    glBindTexture(GL_TEXTURE_2D, senderTextureID)
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
    glBindTexture(GL_TEXTURE_2D, 0)

    # loop
    while(True):
        for event in pygame.event.get():
           if event.type == pygame.QUIT:
               pygame.quit()
               quit()

        ret, frame = cap.read()
        frame = cv2.flip(frame, 1 )
        frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)

        # Copy the frame from the webcam into the sender texture
        glBindTexture(GL_TEXTURE_2D, senderTextureID)
        glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, frame )

        # Send texture to Spout
        # Its signature in C++ looks like this: bool SendTexture(GLuint TextureID, GLuint TextureTarget, unsigned int width, unsigned int height, bool bInvert=true, GLuint HostFBO = 0);
        spoutSender.SendTexture(senderTextureID, GL_TEXTURE_2D, spoutSenderWidth, spoutSenderHeight, False, 0)

        # Clear screen
        glClear(GL_COLOR_BUFFER_BIT  | GL_DEPTH_BUFFER_BIT )
        # reset the drawing perspective
        glLoadIdentity()

        # Draw texture to screen
        glBegin(GL_QUADS)

        glTexCoord(0,0)
        glVertex2f(0,0)

        glTexCoord(1,0)
        glVertex2f(width,0)

        glTexCoord(1,1)
        glVertex2f(width,height)

        glTexCoord(0,1)
        glVertex2f(0,height)

        glEnd()

        # update window
        pygame.display.flip()

        # unbind our sender texture
        glBindTexture(GL_TEXTURE_2D, 0)

if __name__ == "__main__":
    main()
Reply


Messages In This Thread
How to receive webcam capture on spout? - by buzzdarkyear - Jan-12-2022, 12:49 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to receive two passed cmdline parameters and access them inside a Python script? pstein 2 385 Feb-17-2024, 12:29 PM
Last Post: deanhystad
  Receive Input on Same Line? johnywhy 8 810 Jan-16-2024, 03:45 AM
Last Post: johnywhy
  How to continuously receive messages until specified to stop using Bleak jacobbreen25 3 2,218 Dec-28-2022, 04:25 PM
Last Post: jacobbreen25
  How can I add an end line character after every value that I receive? GiggsB 11 5,307 Mar-06-2022, 08:51 PM
Last Post: GiggsB
  How to output Python in Spout or any other video sharing network? buzzdarkyear 4 2,205 Jan-11-2022, 11:37 AM
Last Post: buzzdarkyear
  Rotation Effect on live Webcam Feed Leziiy 0 1,632 Sep-12-2020, 04:25 PM
Last Post: Leziiy
  About Arduino and Python usb webcam tuts Simurg 1 2,195 Mar-20-2020, 07:25 PM
Last Post: Larz60+
  Receive data from Redis RQ worker process freak14 0 1,930 Jul-15-2019, 12:39 PM
Last Post: freak14
  How can I only receive data from selected serial numbers MasterCATZ 7 3,593 Apr-20-2019, 08:35 AM
Last Post: MasterCATZ
  Receive Serial Data and store in different Variables in Python jenkins43 5 5,693 Dec-28-2018, 01:33 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020