OpenViBE forum

The OpenViBE community
It is currently Sun Aug 18, 2019 6:48 am

All times are UTC




Post new topic Reply to topic  [ 12 posts ] 
Author Message
PostPosted: Tue Jun 16, 2015 6:13 pm 
Offline

Joined: Sun Nov 23, 2014 5:32 am
Posts: 21
I have write the following python code to python scripting toolbox, this code will read a matrix (or spatial filters) from a file, and multiply it with the incoming signal, but the problem is that the output will always be zeros, I have print the data before send it to the output pin of the python toolbox, but it's not zeros.
Code:
 # we use numpy to compute the mean of an array of values
import numpy
class MyOVBox(OVBox):
    def __init__(self):
       OVBox.__init__(self)
       self.signalHeader = None

    # The process method will be called by openvibe on every clock tick
    def initialize(self):

    def process(self):

       for chunkIndex in range( len(self.input[0])):
          # if it's a header we save it and send the output header (same as input, except it has only one channel named 'Mean'
          if(type(self.input[0][chunkIndex]) == OVSignalHeader):
             self.signalHeader = self.input[0].pop()
             outputHeader = OVSignalHeader(
             self.signalHeader.startTime,
             self.signalHeader.endTime,
             [1, self.signalHeader.dimensionSizes[1]],
             ['Mean']+self.signalHeader.dimensionSizes[1]*[''],
             self.signalHeader.samplingRate)
             self.output[0].append(outputHeader)

          # if it's a buffer we pop it and put it in a numpy array at the right dimensions
          # We compute the mean and add the buffer in the box output buffer
          elif(type(self.input[0][chunkIndex]) == OVSignalBuffer):
             chunk1 = self.input[0].pop()
             numpyBuffer = numpy.array(chunk1).reshape(tuple(self.signalHeader.dimensionSizes))
        f = open ( '{path_to_file}' , 'r')
        l = numpy.array([ map(float,line.split(',')) for line in f ])
        temp = l.dot(numpyBuffer)   
        temp = numpy.array(temp)
             chunk = OVSignalBuffer(chunk1.startTime, chunk1.endTime, temp.tolist())
        print "chunk = " ,chunk
             #chunk is not equal to zero
             self.output[0].append(chunk)
          # if it's a end-of-stream we just forward that information to the output
          elif(type(self.input[0][chunkIndex]) == OVSignalEnd):
             self.output[0].append(self.input[0].pop())

 # Finally, we notify openvibe that the box instance 'box' is now an instance of MyOVBox.
 # Don't forget that step !!
box = MyOVBox()


also, there is another 3 python scripting toolbox in my scenario, I'm using ubuntu 14.04 and openvibe1.0.0


Top
 Profile  
Reply with quote  
PostPosted: Wed Jun 17, 2015 8:08 am 
Offline

Joined: Tue Dec 04, 2012 3:53 pm
Posts: 778
Location: INRIA Rennes, FRANCE
Hi, does the python-sinus-oscillator.xml box tutorial work and produce output? If yes, then you can copy the solution from there. If not, let us know, then there might be a bug somewhere.


Happy hacking,
Jussi


Top
 Profile  
Reply with quote  
PostPosted: Wed Jun 17, 2015 8:15 am 
Offline

Joined: Sun Nov 23, 2014 5:32 am
Posts: 21
Yes, it's work,instead I have build my based on 'sinus-oscillator' code. also I have pass the variable "chunk1" as an output, and it's work. I have work hardly to see what is going on and I think that the problem is about passing this specific variable "chunk1". the size for this variable is 3-by-128.


Top
 Profile  
Reply with quote  
PostPosted: Wed Jun 17, 2015 8:23 am 
Offline

Joined: Tue Dec 04, 2012 3:53 pm
Posts: 778
Location: INRIA Rennes, FRANCE
Is the size of the output matrix declared correctly in the sending of the header phase? The 3x128 should be declared there. Again, you can use the EBML spy to see whats coming out structurally.


Best,
Jussi


Top
 Profile  
Reply with quote  
PostPosted: Wed Jun 17, 2015 8:27 am 
Offline

Joined: Sun Nov 23, 2014 5:32 am
Posts: 21
I'm sorry I was think that you mean the python code of "sinus-oscillator", I didn't know that there is an xml file. I have run this file, and it's work for a second then the openvibe-designer crashed and gives me the following message:

Quote:
executing script file
terminate called without an active exception
./openvibe-designer.sh: line 54: 5773 Aborted


Top
 Profile  
Reply with quote  
PostPosted: Wed Jun 17, 2015 8:38 am 
Offline

Joined: Sun Nov 23, 2014 5:32 am
Posts: 21
I have change the signal header to make the dimesoinSize = [3, self.signalHeader.dimensionSizes[1]], but the openvibe-designer.sh crashed

Quote:
self.signalHeader = self.input[0].pop()
outputHeader = OVSignalHeader(
self.signalHeader.startTime,
self.signalHeader.endTime,
[3, self.signalHeader.dimensionSizes[1]],
['Mean']+self.signalHeader.dimensionSizes[1]*[''],
self.signalHeader.samplingRate)
self.output[0].append(outputHeader)


after crashing it's gives me the following message :

Quote:
terminate called without an active exception
./openvibe-designer.sh: line 54: 6148 Aborted (core dumped)


Top
 Profile  
Reply with quote  
PostPosted: Wed Jun 17, 2015 2:57 pm 
Offline

Joined: Tue Dec 04, 2012 3:53 pm
Posts: 778
Location: INRIA Rennes, FRANCE
The tutorial scenario works ok for me on OV 1.0.1 and Ubuntu 14.04. Do you have the correct version of Python?

See here,

http://openvibe.inria.fr/tutorial-using ... -openvibe/


Jussi


Top
 Profile  
Reply with quote  
PostPosted: Wed Jun 17, 2015 5:53 pm 
Offline

Joined: Sun Nov 23, 2014 5:32 am
Posts: 21
I have install and build OV 1.0.1, and run the python_sinus_oscillator.xml, the scenario run perfectly for ~ 1 second then the OV designer crashed.
this is the output on the terminal after running this scenario

[
Quote:
INF ] At time 0.000 sec <Box algorithm::(0x00001d15, 0x000035b2) aka Sinus generator> Discovered Python is 2.7.6 (default, Mar 22 2014, 23:03:14)
[GCC 4.8.2] (linux2)
[ INF ] At time 0.000 sec <Box algorithm::(0x00001d15, 0x000035b2) aka Sinus generator> Python Interpreter initialized
[ INF ] At time 0.000 sec <Box algorithm::(0x00001d15, 0x000035b2) aka Sinus generator> executing script file
[ INF ] At time 0.000 sec <Box algorithm::(0x0000432f, 0x00000c65) aka Mean> executing script file
[ INF ] At time 0.000 sec <Box algorithm::(0x000012bf, 0x0000401e) aka Clock stimulator> executing script file
terminate called without an active exception


does python version 2.7.6 makes a problem? should I have only 2.7.3 as said in the documentation?


Top
 Profile  
Reply with quote  
PostPosted: Thu Jun 18, 2015 7:26 am 
Offline

Joined: Tue Dec 04, 2012 3:53 pm
Posts: 778
Location: INRIA Rennes, FRANCE
Unfortunately the scenario runs ok for me on Ubuntu 14.04 using the same Python. Its not possible to say based on your output what goes wrong. You can try

# ./linux-build --debug
# ../dist/openvibe-designer.sh --debug
gdb# run

when it crashes, you should get a backtrace with 'bt'. This trace might tell us something useful, although if the crash happens inside the python code,
its hard to debug this way.


Cheers
Jussi


Top
 Profile  
Reply with quote  
PostPosted: Thu Jun 18, 2015 12:41 pm 
Offline

Joined: Sun Nov 23, 2014 5:32 am
Posts: 21
I did what you told me to do, and the following message appears after debugging

Quote:
Program received signal SIGSEGV, Segmentation fault.
0x00000000 in ?? ()



then I run the designer by command
Code:
 gksudo sh openvibe-designer.sh --debug
and the following message was shown :
Quote:
terminate called without an active exception
xauth: /tmp/libgksu-wWhWj3/.Xauthority
xauth_env: /home/user/.Xauthority
dir: /tmp/libgksu-wWhWj3


In python_sinus_oscillator.xml I removed the spectral Analysis boxes and the scenario works correctly, but in my scenario which does not contains any spectral analysis boxes the scenario still crashed when run.


Top
 Profile  
Reply with quote  
PostPosted: Fri Jun 19, 2015 7:16 am 
Offline

Joined: Tue Dec 04, 2012 3:53 pm
Posts: 778
Location: INRIA Rennes, FRANCE
Thank you for the effort, but unfortunately these don't really reveal what is the problem. :( Usually if there is a problem we can replicate it on the local machine and then debug it with whatever it takes (printfs in the C++ code in the worst case...), but as I said, the thing appears to be working ok for me on Ubuntu 14.04 so there's not much we can do on this end.


Jussi


Top
 Profile  
Reply with quote  
PostPosted: Fri Jun 19, 2015 8:58 am 
Offline

Joined: Sun Nov 23, 2014 5:32 am
Posts: 21
The problem was in my python code :shock: , the dimension label does not meet the dimension size, so I edit my code as follow
Code:
            for jj in range(3):
                dimensionLabels.append( 'channel'+str(jj) )
             dimensionLabels += self.signalHeader.dimensionSizes[1] *[' ']
             print "dimensions label = " , len(dimensionLabels)
             outputHeader = OVSignalHeader(
             self.signalHeader.startTime,
             self.signalHeader.endTime,
             [3, self.signalHeader.dimensionSizes[1]],
             dimensionLabels,
             self.signalHeader.samplingRate)
             self.output[0].append(outputHeader)


The scenario does not crash anymore , but the output is always zero.

My output has [3 , 128] matrix dimension, and the dimension label is as follow : ['channel1' , 'channel2' , 'channel3' , ' ' , ...., ' '] where the number of ' ' is 128, Is that correct? in the tutorial you give, it does not tell what is the dimensionLLabel size or structure.

Thanks,

P.S : for your information , the cause of the crash of sinus oscillator example was power spectrum display box.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group
Americanized by Maƫl Soucaze.