Using Python To Develop Your Vision Algorithm On Your Robot - Final
Using Python To Develop Your Vision Algorithm On Your Robot - Final
VISION ALGORITHM
Alexandre Mazel
Explorer at Nao Labs
USING PYTHON TO DEVELOP YOUR VISION
ALGORITHM
AGENDA FOR TODAY
NAO at a glance
Image Processing
Integration in a choregraphe behavior
Digression: porting to c++ and performance
comparison
NAO AT A GLANCE
NAO FOR EDUCATION
ALDEBARAN
400+ employees in 5 offices worldwide
Worldwide leader in B2A humanoid robotics
5000+ NAO sold over 40 countries
NAO
Platform for education and research purposes
Many contents for all school sectors & levels
5-part
curriculum
with 10 modules
comprehensive introducing
examples Programmin 15 activities for
g with NAO Secondary Education
&
18 activities for
Higher Education
NAO AT A GLANCE
WHAT CAN I DO?
Graphical
Physical
Ergonomic Interface
Development of Simulation Engine to monitor actuators
Behaviors
Behaviors and sensors data
Ergonomic and Simulation and
user-friendly validation
Interface
SDK
Compilation and debugging tools
Access NAO with Matlab, Java, Python, C++, .NET, MS
Robotics Studio
USING PYTHON TO DEVELOP YOUR VISION
ALGORITHM
AGENDA FOR TODAY -
oldies
A. Image Processing
1. Retrieve an image in the python world from NAO camera
2. Process the image
B. Integration in the complete behavior in choregraphe
3. Box and sub boxes
4. Tuning the right head position using video monitor
5. Omnidirectional Walk
6. Installing a time out
7. Various way to finish the behavior
C. Disgression
8. Efficiency compared to c++
9. How to port it to c++ (but why?)
USING PYTHON TO DEVELOP YOUR VISION
ALGORITHM
AGENDA FOR TODAY
NAO at a glance
Image Processing
Integration in a choregraphe behavior
Digression: porting to c++ and performance
comparison
IMAGE PROCESSING IN PYTHON
USING PYTHON TO DEVELOP YOUR VISION
ALGORITHM
NAOQI Vision Architecture
USING PYTHON TO DEVELOP YOUR VISION
ALGORITHM
STANDARD C++ DEVELOPMENT
Debug
Cross compile the module
Send it to your NAO
Relaunch Naoqi
See results
Test
Cross compile the module
Send it to your NAO
Relaunch Naoqi
See results
Tune
Cross compile the module
Relaunch Naoqi
See results
USING PYTHON TO DEVELOP YOUR VISION
ALGORITHM
DEVELOPMENT IN CHOREGRAPHE
Write python
Run the code (press F5)
Debug
Run the code (press F5)
Test
Run the code (press F5)
Tune
Run the code (press F5)
USING PYTHON TO DEVELOP YOUR VISION
ALGORITHM
RETRIEVING AN IMAGE: SUBS
img = self.getImageFromCamera();
img contains now a numpy buffer, you can use all numpy and OpenCV2
functions on it!
As a quick glimpse:
NAO at a glance
Image Processing
Integration in a choregraphe behavior
Digression about performance
USING PYTHON TO DEVELOP YOUR VISION
ALGORITHM
PROCESSING A LINE FOLLOWER
Step 3: Find the abscissa of the first white pixel using numpy.argmax
USING PYTHON TO DEVELOP YOUR VISION
ALGORITHM
PROCESSING A LINE FOLLOWER
aNonZeroIdx = numpy.where(aMaxL != 0)[0]; # here we retravelling thru the list, it's not optimal (TODO: optimise!)
nFirstNonZero = aNonZeroIdx[0];
nLastNonZero = aNonZeroIdx[-1];
nHeightSampling = nLastNonZero - nFirstNonZero;
aLine = aMaxLWithoutZeros;
rOrientation = ((rTop-rBase))/nHeightSampling; # WRN: here it could be wrong as the aLine has zero removed, so perhaps the top and bottom are not at top
or bottom !
Let's jump to choregraphe!
DIGRESSION
USING PYTHON TO DEVELOP YOUR VISION
ALGORITHM
DIGRESSION port to c+
+
Python:
kernel = -numpy.ones((1,3), dtype=numpy.float)
kernel[0,1] = 2
img = cv2.filter2D(img, -1, kernel)
C++:
int nKernelRows = 1;
int nKernelCols = 3;
kernel = cv::Mat::ones( nKernelRows, nKernelCols, CV_32F );
cv::filter2D(img_GreyScale, img_GreyScale, -1 , kernel,
cv::Point( -1, -1 ), 0,
cv::BORDER_DEFAULT );
USING PYTHON TO DEVELOP YOUR VISION
ALGORITHM
DIGRESSION port to c+
+
Python:
retval, img = cv2.threshold( img, 45, 255, cv2.THRESH_TOZERO )
C++:
// thresholding to remove low differential
cv::threshold( img_GreyScale, img_GreyScale, 45, 255,
cv::THRESH_TOZERO );
USING PYTHON TO DEVELOP YOUR VISION
ALGORITHM
DIGRESSION port to c+
+
Python:
aMaxLWithoutZeros = aMaxL[aMaxL>0];
C++:
std::vector<int> aMaxLWithoutZeros;
aMaxLWithoutZeros.reserve( nHeight );
for( unsigned int i =0; i < nHeight; ++i)
{
val = aMaxL[i];
if (val > 0)
{
aMaxLWithoutZeros.push_back( val );
}
}
USING PYTHON TO DEVELOP YOUR VISION
ALGORITHM
DIGRESSION port to c+
+
Python:
buffer conversion to numpy: 5ms
detectLines: 14 ms
C++:
buffer conversion: 0ms (none)
detectLines: 5 ms
THANK YOU FOR YOUR ATTENTION !
Contact us for more info:
education@aldebaran-robotics.com
NAOAcademics
@NAOAcademics