Commit ee05bd33 authored by Evgeny Kusmenko's avatar Evgeny Kusmenko
Browse files

Merge branch 'adi-dev' into 'master'

Adi dev

See merge request !1
parents f5baf0ce 07445d58
# (c)
- linux
stage: linux
- chmod +x
- ./
- .gitignore
\ No newline at end of file
File added
cmake_minimum_required(VERSION 3.5)
project (default)
<!-- (c) -->
# BallTracking
## Prerequisites
1. Ubuntu Linux 16.04 LTS or 18.04 LTS (experimental)
2. Armadillo (at least armadillo version 6.600 must be used) [Official instructions at Armadillo Website](
3. OpenCV.
## How to Run
Generate and build the code for the EMAM model by executing:
Finally, run the BallTracking-Video as follows:
You can try different videos to track a yellow object or object with different color by setting the corresponding values to CVInRange-variables in _BallTracking.cpp_.
\ No newline at end of file
rm -rf target
java -jar embedded-montiarc-math-generator-0.1.16-SNAPSHOT-jar-with-dependencies.jar -m src/main/emam/ -r ba.ballTracking -o target -flag-generate-cmake
cd target
sed -i 's/cube/Cube<unsigned char>/g' ba_ballTracking.h
cd ..
rm -rf build
mkdir build && cd build
echo "Building BallTracking.."
cmake ..
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="" xmlns:xsi=""
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns=""
<!-- Optional URL to server. Default value is http://localhost:9000 -->
<releases><enabled /></releases>
<snapshots><enabled /></snapshots>
<releases><enabled /></releases>
<snapshots><enabled /></snapshots>
<releases><enabled /></releases>
<snapshots><enabled /></snapshots>
#include "ba_ballTracking.h"
#include "ConvHelper.h"
#include <opencv2/highgui/highgui.hpp>
#include <armadillo>
using namespace arma;
using std::string;
int main(int argc, const char** argv) {
string filename = "BallTrack.mp4";
cv::VideoCapture capture(filename);
cv::Mat frame;
if (!capture.isOpened()) {
throw "Error when trying to read BallTrack.mp4";
ba_ballTracking ballT_Object;
ballT_Object.sizeXIn = 11;
ballT_Object.sizeYIn = 11;
ballT_Object.sigmaXIn = 0;
ballT_Object.sigmaYIn = 0;
ballT_Object.colorConversionIn = 40;
ballT_Object.lowerBoundaryIn = { 20, 100, 100 };
ballT_Object.upperBoundaryIn = { 30, 255, 255 };
ballT_Object.erosion_elemIn = 0;
ballT_Object.iterationsIn1 = 2;
ballT_Object.dilation_elemIn = 0;
ballT_Object.iterationsIn2 = 2;
ballT_Object.modeIn = 0;
ballT_Object.methodIn = 2;
ballT_Object.colorIn = { 0,0,0 };
ballT_Object.thicknessIn = 4;
ballT_Object.lineTypeIn = 4;
cv::namedWindow("w", 1);
for ( ; ; ) {
capture >> frame;
if (frame.empty())
ballT_Object.imageIn = to_armaCube<unsigned char, 3>(frame);
cv::Mat output_frame = to_cvmat<unsigned char>(ballT_Object.modImageOut);
// cv::flip(output_frame, output_frame, 0);
cv::imshow("w", output_frame);
cmake_minimum_required(VERSION 3.5)
project(BallTracking CXX)
add_executable(BallTracking BallTracking.cpp)
set_target_properties(BallTracking PROPERTIES LINKER_LANGUAGE CXX)
find_package(OpenCV REQUIRED)
set(LIBS ${LIBS} ${OpenCV_LIBS})
target_include_directories(BallTracking PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(BallTracking ba_ballTracking ${LIBS} -lblas -lopenblas)
export(TARGETS BallTracking FILE BallTracking.cmake)
/* (c) */
package ba;
component BallTracking{
in Q^{960,720,3} imageIn,
//GaussianBlur ports
in Z sizeXIn,
in Z sizeYIn,
in Q sigmaXIn,
in Q sigmaYIn,
//CvtColor ports
in Z colorConversionIn,
//InRange ports
in Q^{3} lowerBoundaryIn,
in Q^{3} upperBoundaryIn,
//Erode ports
in Z erosion_elemIn,
in Z iterationsIn1,
//Dilate ports
in Z dilation_elemIn,
in Z iterationsIn2,
//FindContours ports
in Z modeIn,
in Z methodIn,
//RectAngle ports
in Q^{3} colorIn,
in Z thicknessIn,
in Z lineTypeIn,
// i want to input the image again
out Q^{960,720,3} modImageOut;
instance CVGaussianBlur<960,720> gaussBlur;
instance CVCvtColor<960,720> cvtColor;
instance CVInRange<960,720> inRange;
instance CVErode<960,720> erode;
instance CVDilate<960,720> dilate;
instance CVFindContours<960,720> findContours;
instance CVLargestContour largestContour;
instance CVBoundingRect boundingRect;
instance CVRectangle<960,720> rectAngle;
connect imageIn -> gaussBlur.src;
connect sizeXIn -> gaussBlur.sizeX;
connect sizeYIn -> gaussBlur.sizeY;
connect sigmaXIn -> gaussBlur.sigmaX;
connect sigmaYIn -> gaussBlur.sigmaY;
connect gaussBlur.dst -> cvtColor.src;
connect colorConversionIn -> cvtColor.colorConversion;
connect cvtColor.dst -> inRange.src;
connect lowerBoundaryIn -> inRange.lowerBoundary;
connect upperBoundaryIn -> inRange.upperBoundary;
connect inRange.dst -> erode.src;
connect erosion_elemIn -> erode.erosion_elem;
connect iterationsIn1 -> erode.iterations;
connect erode.dst -> dilate.src;
connect dilation_elemIn -> dilate.dilation_elem;
connect iterationsIn2 -> dilate.iterations;
connect dilate.dst -> findContours.image;
connect modeIn -> findContours.mode;
connect methodIn -> findContours.method;
connect findContours.contours -> largestContour.contours;
connect largestContour.lContour -> boundingRect.contour;
connect boundingRect.rect -> rectAngle.rect;
connect imageIn -> rectAngle.src;
connect colorIn -> rectAngle.color;
connect thicknessIn -> rectAngle.thickness;
connect lineTypeIn -> rectAngle.lineType;
//how to connect the src Image here as input
connect rectAngle.outputImg -> modImageOut;
\ No newline at end of file
package ba;
component CVBoundingRect {
in Q contour,
out Q rect;
implementation Math {
rect = boundingRect(contour);
\ No newline at end of file
package ba;
component CVCvtColor<N n =960,N m=720> {
in Q^{n,m,3} src,
in Z colorConversion,
out Q^{n,m,3} dst;
implementation Math{
dst = cvtColor(src, colorConversion);
\ No newline at end of file
package ba;
component CVDilate<N n=960,N m=720> {
in Q^{n,m} src,
in Z dilation_elem,
in Z iterations,
out Q^{n,m} dst;
implementation Math{
dst = dilate(src, dilation_elem, iterations);
\ No newline at end of file
package ba;
component CVErode<N n=960,N m=720> {
in Q^{n,m} src,
in Z erosion_elem,
in Z iterations,
out Q^{n,m} dst;
implementation Math{
dst = erode(src, erosion_elem, iterations);
\ No newline at end of file
package ba;
component CVFindContours<N n=960,N m=720> {
in Q^{n,m} image,
in Z mode,
in Z method,
out Q contours;
implementation Math {
contours = findContours(image, mode, method);
\ No newline at end of file
package ba;
component CVGaussianBlur<N n=960,N m=720> {
in Q^{n,m,3} src,
in Z sizeX,
in Z sizeY,
in Q sigmaX,
in Q sigmaY,
out Q^{n,m,3} dst;
implementation Math {
dst = gaussianBlur(src, sizeX, sizeY, sigmaX, sigmaY);
\ No newline at end of file
package ba;
component CVInRange<N n=960,N m=720> {
in Q^{n,m,3} src,
in Q^{3} lowerBoundary,
in Q^{3} upperBoundary,
out Q^{n,m} dst;
implementation Math{
dst = inRange(src, lowerBoundary, upperBoundary);
package ba;
component CVLargestContour{
in Q contours,
out Q lContour;
implementation Math{
lContour = largestContour(contours);
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment