Hello, I need help, I installed myrobotlab and I can not work or I this example amended or any service that has the opencv. 
I can not print the data in Phithon.
 
# This code creates an opencv service and tracks a face. 
# It thens finds the center of the face and converts the position to a scale of 1-100
# This information is then sent via serial service to any receiving device
 
# If the script needs to be restarted, completely close MRL and reopen it.
# 8/27/13
 
import time
 
from java.lang import String
from java.lang import Class
from java.awt import Rectangle
from org.myrobotlab.service import Runtime
from org.myrobotlab.service import OpenCV
from org.myrobotlab.opencv import OpenCVData
from com.googlecode.javacv.cpp.opencv_core import CvPoint;
from org.myrobotlab.service import OpenCV
 
# create or get a handle to an OpenCV service
opencv = Runtime.createAndStart("opencv","OpenCV")
 
# Convert the video to Black and White
opencv.addFilter("Gray1", "Gray")                             # Sometimes gray seems to help
# reduce the size - face tracking doesn't need much detail. The smaller the faster
opencv.addFilter("PyramidDown1", "PyramidDown")
#opencv.addFilter("PyramidDown2", "PyramidDown")
# add the face detect filter
opencv.addFilter("FaceDetect1", "FaceDetect")
 
# Other OpenCV filter packages to play with
#Package 1: Facedetect in range
#opencv.addFilter("PyramidDown1", "PyramidDown")
#opencv.addFilter("InRange1", "InRange")
#opencv.setFilterCFG("InRange1","hueMin", "0")
#opencv.setFilterCFG("InRange1","hueMax", "248")
#opencv.setFilterCFG("InRange1","saturationMin", "0")
#opencv.setFilterCFG("InRange1","saturationMax", "256")
#opencv.setFilterCFG("InRange1","valueMin", "62")
#opencv.setFilterCFG("InRange1","valueMax", "178")
#opencv.setFilterCFG("InRange1","useHue", True)
#opencv.setFilterCFG("InRange1","useSaturation", True)
#opencv.setFilterCFG("InRange1","useValue", True)
#opencv.addFilter("FaceDetect1", "FaceDetect")
 
#package 2: Find yellow thing
#opencv.addFilter("PyramidDown1", "PyramidDown")
#opencv.addFilter("InRange1", "InRange")
#opencv.setFilterCFG("InRange1","hueMin", "10")
#opencv.setFilterCFG("InRange1","hueMax", "34")
#opencv.setFilterCFG("InRange1","saturationMin", "87")
#opencv.setFilterCFG("InRange1","saturationMax", "139")
#opencv.setFilterCFG("InRange1","valueMin", "128")
#opencv.setFilterCFG("InRange1","valueMax", "187")
#opencv.setFilterCFG("InRange1","useHue", True)
#opencv.setFilterCFG("InRange1","useSaturation", True)
#opencv.setFilterCFG("InRange1","useValue", True)
#opencv.setFilter("FindContours1", "FindContours")
 
#create a Serial service named serial
 
 
# This function is called every time the OpenCV service has data available.
# This will depend on the framerate of the video, but will probably be 
# somewhere around 15 times a second.
def input():
    global x
    global y
    global sposx
    global sposy
    global posx
    global posy
 
    # Get OpenCV data
    opencvData = msg_opencv_publishOpenCVData.data[0]
 
    if (opencvData.getBoundingBoxArray().size() > 0) :    # If the box surrounding a face exists
     rect = opencvData.getBoundingBoxArray().get(0)       # Store the information in rect
     posx = rect.x                                        # Get the x position of the corner
     posy = rect.y                                        # Get the y position of the corner
 
     w = rect.width                                       # Get the width
     h = rect.height                                      # Get the height
     sposx = (w/2)
     sposy = (h/2)
     # Get the x and y of the center in pixels. Origin is in top left corner
     x = (posx + sposx)  
     y = (posy + sposy)
     
     # Convert x,y pixels to (x,y) coordinates from top left.
     # Note that 320 and 240 will need to be changed if another pyramid down is used
     # It may also need to be changed depending on your cameras specifications.
     # This gets the position in a scale from 1, 100
     x = int(translate(x, 1, 320, 1, 100));                  # translate() works the same way the Arduino map() function would
     y = int(translate(y, 1, 140, 1, 100));
     
     print "x: "  ,x                                       # print x to the python readout
     print 'y: '  ,y                                       # print y to the python readout
     return object
     
opencv.addListener("publishOpenCVData", python.name, "input");
 
# opencv.setCameraIndex(1)
 
opencv.capture()

 

MaVo

10 years 2 months ago

Hello mecax and welcome!

Where did you get this script from? It's old.

In newer versions, functions take arguments und don't have to get the data themselves.

Also "translate()" doesn't work (anymore), I don't know more about this, GroG (or someone else) has to look at this.

Here a corrected version:

1. the thing with parameters to functions

2. translate() - just commented it out, so it works again, but it's leaving out the mapping, so it's not the final version

import time
 
from java.lang import String
from java.lang import Class
from java.awt import Rectangle
from org.myrobotlab.service import Runtime
from org.myrobotlab.service import OpenCV
from org.myrobotlab.opencv import OpenCVData
from com.googlecode.javacv.cpp.opencv_core import CvPoint;
from org.myrobotlab.service import OpenCV
 
# create or get a handle to an OpenCV service
opencv = Runtime.createAndStart("opencv","OpenCV")
 
# Convert the video to Black and White
opencv.addFilter("Gray1", "Gray")                             # Sometimes gray seems to help
# reduce the size - face tracking doesn't need much detail. The smaller the faster
opencv.addFilter("PyramidDown1", "PyramidDown")
#opencv.addFilter("PyramidDown2", "PyramidDown")
# add the face detect filter
opencv.addFilter("FaceDetect1", "FaceDetect")
 
# Other OpenCV filter packages to play with
#Package 1: Facedetect in range
#opencv.addFilter("PyramidDown1", "PyramidDown")
#opencv.addFilter("InRange1", "InRange")
#opencv.setFilterCFG("InRange1","hueMin", "0")
#opencv.setFilterCFG("InRange1","hueMax", "248")
#opencv.setFilterCFG("InRange1","saturationMin", "0")
#opencv.setFilterCFG("InRange1","saturationMax", "256")
#opencv.setFilterCFG("InRange1","valueMin", "62")
#opencv.setFilterCFG("InRange1","valueMax", "178")
#opencv.setFilterCFG("InRange1","useHue", True)
#opencv.setFilterCFG("InRange1","useSaturation", True)
#opencv.setFilterCFG("InRange1","useValue", True)
#opencv.addFilter("FaceDetect1", "FaceDetect")
 
#package 2: Find yellow thing
#opencv.addFilter("PyramidDown1", "PyramidDown")
#opencv.addFilter("InRange1", "InRange")
#opencv.setFilterCFG("InRange1","hueMin", "10")
#opencv.setFilterCFG("InRange1","hueMax", "34")
#opencv.setFilterCFG("InRange1","saturationMin", "87")
#opencv.setFilterCFG("InRange1","saturationMax", "139")
#opencv.setFilterCFG("InRange1","valueMin", "128")
#opencv.setFilterCFG("InRange1","valueMax", "187")
#opencv.setFilterCFG("InRange1","useHue", True)
#opencv.setFilterCFG("InRange1","useSaturation", True)
#opencv.setFilterCFG("InRange1","useValue", True)
#opencv.setFilter("FindContours1", "FindContours")
 
#create a Serial service named serial
 
 
# This function is called every time the OpenCV service has data available.
# This will depend on the framerate of the video, but will probably be
# somewhere around 15 times a second.
def input(opencvData):
    global x
    global y
    global sposx
    global sposy
    global posx
    global posy
 
    if (opencvData.getBoundingBoxArray().size() > 0) :    # If the box surrounding a face exists
     rect = opencvData.getBoundingBoxArray().get(0)       # Store the information in rect
     posx = rect.x                                        # Get the x position of the corner
     posy = rect.y                                        # Get the y position of the corner
 
     w = rect.width                                       # Get the width
     h = rect.height                                      # Get the height
     sposx = (w/2)
     sposy = (h/2)
     # Get the x and y of the center in pixels. Origin is in top left corner
     x = (posx + sposx)  
     y = (posy + sposy)
     
     # TODO - this needs the work - ??? translate ???
     # Convert x,y pixels to (x,y) coordinates from top left.
     # Note that 320 and 240 will need to be changed if another pyramid down is used
     # It may also need to be changed depending on your cameras specifications.
     # This gets the position in a scale from 1, 100
     #x = int(translate(x, 1, 320, 1, 100));                  # translate() works the same way the Arduino map() function would
     #y = int(translate(y, 1, 140, 1, 100));
     
     print "x: "  ,x                                       # print x to the python readout
     print 'y: '  ,y                                       # print y to the python readout
     return object
     
opencv.addListener("publishOpenCVData", python.name, "input");
 
# opencv.setCameraIndex(1)
 
opencv.capture()

Hope this helps!

thanks  Ma. Vo., it was the input that was incomplete, now he's great. and thanks for the welcome