Hey everyone! Excellent site! I'm a Python/Java newb in need of help. I just installed the current MRL and the latest Java (9). I tested the Opencv face-tracking on the GUI interface and it tracks my face fine on my built-in laptop camera.

But in trying to set up a Python connection to my Arduino Uno board so I can set up a moving camera to follow faces, I can't get past these syntax errors. I've formatted this code (Face_Detect_Serial.py from docs at Google) as best I know how, but all the imports were troublesome. As you can see, I've had to import entire libs like java.lang instead of just using the 'from' parameter. But if that still gets me what I want, I can live with it for now.

My real problem is getting two opencv imports going. I've highlighted the code and the error messages in order below that. I'm a dinosaur coder from the COBOL days, but I've worked in BASIC & VB, and with Arduinos fore a year now, so I'm starting to get comfortable in C++. But I'm too new to Python to know how to handle libs with opencv.

I get that this is a lot of verbeage - I'm funny that way - but I'd sure appreciate some help:

-------------------------------

# 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 java.awt                         #Class
import org.myrobotlab.service             #rectangle
import org.myrobotlab.service             #Runtime  
import org.myrobotlab #import openCV  #.opencv
import com.googlecode.javacv.cpp.opencv_core #import OpenCVData #  
import org.myrobotlab.service             #CvPoint  
import OpenCV

# create or get a handle to an OpenCV
serviceopencv = 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
fasteropencv.addFilter("PyramidDown1", "PyramidDown")
# add the face detect
filteropencv.addFilter("FaceDetect1", "FaceDetect")

. . .

(from two different runs, the second one  having had the first opencv import line commented out)

------Traceback (most recent call last):  File string, line 13, in moduleImportError: No module named googlecode    at org.python.core.Py.ImportError(Py.java:328)    at org.python.core.imp.import_logic(imp.java:912)    at org.python.core.imp.import_module_level(imp.java:978)    at org.python.core.imp.importName(imp.java:1062)    at org.python.core.ImportFunction.__call__(__builtin__.java:1280)    at org.python.core.PyObject.__call__(PyObject.java:431)    at org.python.core.__builtin__.__import__(__builtin__.java:1232)    at org.python.core.imp.importOne(imp.java:1081)    at org.python.pycode._pyx12.f$0(string:85)    at org.python.pycode._pyx12.call_function(string)    at org.python.core.PyTableCode.call(PyTableCode.java:167)    at org.python.core.PyCode.call(PyCode.java:18)    at org.python.core.Py.runCode(Py.java:1386)    at org.python.core.Py.exec(Py.java:1430)    at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:267)    at org.myrobotlab.service.Python$PIThread.run(Python.java:161)------
 

------Traceback (most recent call last):  File string, line 15, in moduleImportError: No module named OpenCV    at org.python.core.Py.ImportError(Py.java:328)    at org.python.core.imp.import_first(imp.java:877)    at org.python.core.imp.import_module_level(imp.java:972)    at org.python.core.imp.importName(imp.java:1062)    at org.python.core.ImportFunction.__call__(__builtin__.java:1280)    at org.python.core.PyObject.__call__(PyObject.java:431)    at org.python.core.__builtin__.__import__(__builtin__.java:1232)    at org.python.core.imp.importOne(imp.java:1081)    at org.python.pycode._pyx14.f$0(string:85)    at org.python.pycode._pyx14.call_function(string)    at org.python.core.PyTableCode.call(PyTableCode.java:167)    at org.python.core.PyCode.call(PyCode.java:18)    at org.python.core.Py.runCode(Py.java:1386)    at org.python.core.Py.exec(Py.java:1430)    at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:267)    at org.myrobotlab.service.Python$PIThread.run(Python.java:161)------

Mats

7 years 2 months ago

Hi mnewley59 and welcome to MRL.
 
First a few important things to know: 
 
Python in MRL is not actually Python. MRL uses Jython, a Java implementation of Python
So you may find Python libraries that cant' be used like for example numpy and scipy.
 
MRL changes fast. The code you found is about 3 years old so a bit old.
 
I looked at the code you try to use, and It can be boiled down to this worky code. No need for any of the imports. I guess that you have more code after the .... 
 
# create or get a handle to an OpenCV
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
opencv.addFilter("PyramidDown1", "PyramidDown")
# add the face detect
opencv.addFilter("FaceDetect1", "FaceDetect")
opencv.capture()
 
/Mats