Python Forum
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python OSC
#1
So, i'm using this python OSC https://pypi.python.org/pypi/python-osc

I see the example and try to replicate it with my code, but i'm havin a syntax problem with a line that's been used on the example.

import argparse
import numpy as np
import cv2

from pythonosc import osc_message_builder
from pythonosc import udp_client

frame = cv2.VideoCapture(0)

#frame.set(cv2.CV_CAP_PROP_FRAME_WIDTH,320);
#frame.set(cv2.CV_CAP_PROP_FRAME_HEIGHT,240);

disponible,fotograma = frame.read()
newfotograma = cv2.resize (fotograma,(320,240))
alto, ancho, channel = newfotograma.shape

altoC, anchoC, channelC = fotograma.shape

AnteriorGray = cv2.cvtColor(newfotograma, cv2.COLOR_BGR2GRAY)

parser = argparse.ArgumentParser()
parser.add_argument("--ip", default="127.0.0.1",
#help="The ip of the OSC server")
parser.add_argument("--port", type=int, default=12347,
#help="The port the OSC server is listening on")
args = parser.parse_args()
            
client = udp_client.SimpleUDPClient(args.ip, args.port)  #this line has a syntax error but is from the example



def draw_flow(w,h,flow, step=1):
    emptyImg = cv2.resize(img,(w,h))

    for j in range (0,alto,step):
        for i in range (0,ancho,step):
            U=flow.item(j,i,0)
            V=flow.item(j,i,1)
            SX=int(i+U)
            SY=int(j+V)
            #cv2.line(emptyImg,(i*2,j*2),(SX*2,SY*2),(255,0,0))
            cv2.line(emptyImg,(i*2,480),(SX*2,300),(SY,SY,SY))
            cv2.line(emptyImg,((i+10)*2,480),((SX+10)*2,SY+300),(SX,SX,SX))
            cv2.line(emptyImg,((i+5)*2,480),((SX+5)*2,SY+300),(SX,SX,SX))
            #cv2.line(emptyImg,(0,0),(20,20),(0,0,255))
            #print ("U",U)
            #print ("i",i)
            #print ("SX",SX)
            
            if( 0<i<25 and (U>1) ):
                enviando = 12
                print(enviando)
                client.send_message("/actuador2", enviando()
            if(25<i<50 and U>1):
                print(13)
            if(50<i<75 and U>1):
                print(14)    
            if(75<i<100 and U>1):
                print(15)
            if(100<i<125 and U>1):
                print(16)
            if(125<i<150 and U>1):
                print(17)
            if(150<i<175 and U>1):
                print(18)
            if(175<i<200 and U>1):
                print(19)
            if(200<i<225 and U>1):
                print(20)
            if(225<i<250 and U>1):
                print(21)
            if(250<i<275 and U>1):
                print(22)
            if(275<i<300 and U>1):
                print(23)

    return emptyImg


while True:
    key  = cv2.waitKey(1)
    disponible, img = frame.read()
    newimg = cv2.resize (img,(320,240))
    ActualGray = cv2.cvtColor(newimg, cv2.COLOR_BGR2GRAY)

    if(disponible==True):
        
        
        
        flow = cv2.calcOpticalFlowFarneback(AnteriorGray, ActualGray, None, 0.5, 3, 15, 3, 5, 1.2, 0) 
        salida = draw_flow(640,480,flow,20)
        

                
        cv2.imshow("Flow",salida)
        cv2.imshow ( "pequeña", newimg)
        AnteriorGray = ActualGray
        
        if __name__ == "__main__":
            parser = argparse.ArgumentParser()
            parser.add_argument("--ip", default="127.0.0.1",
                                help="The ip of the OSC server")
            parser.add_argument("--port", type=int, default=12347,
                                help="The port the OSC server is listening on")
            args = parser.parse_args()
            
            client = udp_client.SimpleUDPClient(args.ip, args.port)


    client.send_message("/filter", enviando())

                
        
    if key == ord('q'):
        break;
        
frame.release()
cv2.destroyAllWindows()
Any one can help me?
Reply


Messages In This Thread
Python OSC - by andrea0913 - Nov-20-2017, 11:52 PM
RE: Python OSC - by sparkz_alot - Nov-21-2017, 02:23 AM
RE: Python OSC - by andrea0913 - Nov-21-2017, 04:12 AM
RE: Python OSC - by Larz60+ - Nov-21-2017, 12:09 PM
RE: Python OSC - by buran - Nov-21-2017, 12:29 PM

Forum Jump:

User Panel Messages

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