Commit c8202d6f authored by Evgeny Kusmenko's avatar Evgeny Kusmenko

Merge branch 'adi-dev' into 'master'

enable more compatibility with cv

See merge request !42
parents f0ec78ea d8c233fa
Pipeline #273552 passed with stage
in 21 minutes and 44 seconds
......@@ -79,7 +79,7 @@ public abstract class MathCommand {
return "";
}
public void redefineArmaMat(BluePrintCPP bluePrint){
public static void redefineArmaMat(BluePrintCPP bluePrint){
List<Variable> vars= bluePrint.getVariables();
for(Variable var : vars){
VariableType varType = var.getVariableType();
......@@ -96,7 +96,7 @@ public abstract class MathCommand {
}
}
public void redefineInit(BluePrintCPP bluePrint){
public static void redefineInit(BluePrintCPP bluePrint){
Optional<Method> methodOpt = bluePrint.getMethod("init");
Method initMethod = methodOpt.get();
List<Instruction> instructs = initMethod.getInstructions();
......
......@@ -7,15 +7,13 @@ import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instance
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAPortInstanceSymbol;
import de.monticore.lang.embeddedmontiarcdynamic.embeddedmontiarcdynamic._symboltable.instanceStructure.EMADynamicComponentInstanceSymbol;
import de.monticore.lang.math._symboltable.MathStatementsSymbol;
import de.monticore.lang.math._symboltable.expression.MathExpressionSymbol;
import de.monticore.lang.monticar.generator.*;
import de.monticore.lang.monticar.generator.cmake.CMakeConfig;
import de.monticore.lang.monticar.generator.cmake.CMakeFindModule;
import de.monticore.lang.monticar.generator.cpp.Dynamics.DynamicHelper;
import de.monticore.lang.monticar.generator.cpp.Dynamics.EventPortValueCheck;
import de.monticore.lang.monticar.generator.cpp.converter.ExecuteMethodGenerator;
import de.monticore.lang.monticar.generator.cpp.converter.MathConverter;
import de.monticore.lang.monticar.generator.cpp.converter.OptimizationSymbolHandler;
import de.monticore.lang.monticar.generator.cpp.converter.TypeConverter;
import de.monticore.lang.monticar.generator.cpp.converter.*;
import de.monticore.lang.monticar.generator.cpp.BluePrintCPP.*;
import de.monticore.lang.monticar.generator.cpp.mathopt.MathOptSolverConfig;
import de.monticore.lang.monticar.generator.cpp.template.AllTemplates;
......@@ -55,6 +53,7 @@ public class GeneratorCPP implements Generator {
protected boolean generateSimulatorInterface = false;
protected boolean checkModelDir = false;
protected boolean streamTestGenerationMode = false;
public boolean isGenerateCV = false;
// CMake
private boolean generateCMake = false;
......@@ -179,8 +178,6 @@ public class GeneratorCPP implements Generator {
//setGenerateMainClass(true);
}
currentFileContentList = fileContents;
if (!streamTestGenerationMode)
fileContents.add(new FileContent(generateString(taggingResolver, componentInstanceSymbol, symtab), componentInstanceSymbol));
......@@ -200,7 +197,6 @@ public class GeneratorCPP implements Generator {
Log.info(generateComponentInstance + "", "Bool:");
}
if (generateComponentInstance) {
fileContents.addAll(generateStrings(taggingResolver, instanceSymbol, symtab));
}
}
......@@ -234,8 +230,6 @@ public class GeneratorCPP implements Generator {
}
}
if (shouldGenerateMainClass()) {
//fileContents.add(getMainClassFileContent(componentInstanceSymbol, fileContents.get(0)));
} else if (shouldGenerateSimulatorInterface()) {
......@@ -261,8 +255,10 @@ public class GeneratorCPP implements Generator {
fileContents.addAll(generateStrings(taggingResolver, componentInstanceSymbol, symtab));
}
}
} else
} else {
searchForCVEverywhere(componentSymbol, symtab);
fileContents = generateStrings(taggingResolver, componentSymbol, symtab);
}
fileContents.addAll(generateTypes(TypeConverter.getTypeSymbols()));
fileContents.addAll(handleTestAndCheckDir(symtab, componentSymbol));
if (isGenerateAutopilotAdapter()) {
......@@ -563,4 +559,26 @@ public class GeneratorCPP implements Generator {
public OptimizationSymbolHandler getMathOptExecuteMethodGenerator() {
return mathOptExecuteMethodGenerator;
}
public void searchForCVEverywhere(EMAComponentInstanceSymbol componentInstanceSymbol, Scope symtab){
MathStatementsSymbol mathStatementsSymbol = Helper.getMathStatementsSymbolFor(componentInstanceSymbol, symtab);
if(mathStatementsSymbol != null) {
List<MathExpressionSymbol> mathExpressionSymbols = mathStatementsSymbol.getMathExpressionSymbols();
for(MathExpressionSymbol mathExpressionSymbol : mathExpressionSymbols){
String nameOfFunction = ComponentConverter.getNameOfMathCommand(mathExpressionSymbol);
MathCommand mathCommand = this.mathCommandRegister.getMathCommand(nameOfFunction);
if(mathCommand != null){
if(mathCommand.isCVMathCommand()){
this.isGenerateCV = true;
}
}
}
}
for (EMAComponentInstanceSymbol instanceSymbol : componentInstanceSymbol.getSubComponents()) {
searchForCVEverywhere(instanceSymbol, symtab);
}
}
}
......@@ -41,7 +41,7 @@ public class ComponentConverter {
bluePrint.setOriginalSymbol(componentSymbol);
bluePrint.addDefineGenerics(componentSymbol);
addVariables(componentSymbol, bluePrint);
// ToDo: you can fix the variables type here or later, so before it will be used
BluePrintFixer.fixBluePrintDynamicVariableConnectRequestQueues(bluePrint);
......@@ -120,7 +120,10 @@ public class ComponentConverter {
bluePrint.addAdditionalIncludeString("DynamicHelper");
}
}
if(generatorCPP.isGenerateCV){
MathCommand.redefineArmaMat(bluePrint);
MathCommand.redefineInit(bluePrint);
}
return bluePrint;
}
......
......@@ -4,64 +4,44 @@
#define M_PI 3.14159265358979323846
#endif
#include "armadillo"
#include "opencv2/imgproc.hpp"
#include "ConvHelper.h"
#include <vector>
#include "test_math_erodeAndGaussianBlurCommandTest_gaussBlur.h"
#include "test_math_erodeAndGaussianBlurCommandTest_arm.h"
#include "test_math_erodeAndGaussianBlurCommandTest_cvtColor.h"
using namespace arma;
using namespace std;
class test_math_erodeAndGaussianBlurCommandTest{
public:
Cube<unsigned char> src;
int erosion_elemIn;
colvec sizeY;
colvec two;
cv::Mat dst;
cv::Mat dst3;
Cube<unsigned char> outMatrix;
arma::Mat<unsigned char> out2Matrix;
Cube<unsigned char> imageIn;
int sizeXIn;
int sizeYIn;
double sigmaXIn;
double sigmaYIn;
int colorConversionIn;
Cube<unsigned char> modImageOut;
test_math_erodeAndGaussianBlurCommandTest_gaussBlur gaussBlur;
test_math_erodeAndGaussianBlurCommandTest_arm arm;
test_math_erodeAndGaussianBlurCommandTest_cvtColor cvtColor;
void init()
{
src = Cube<unsigned char>(n, m, 3);
sizeY=colvec(3);
two=colvec(2);
outMatrix = Cube<unsigned char>(3, n, m);
out2Matrix=Mat<unsigned char>(2,m);
}
void erodeHelper(const Cube<unsigned char>& src, cv::Mat& dst, int erosion_elem, int iterations)
{
int erosion_type = 0;
if( erosion_elem == 0 ){ erosion_type = cv::MORPH_RECT; }
else if( erosion_elem == 1 ){ erosion_type = cv::MORPH_CROSS; }
else if( erosion_elem == 2) { erosion_type = cv::MORPH_ELLIPSE; }
int erosion_size = erosion_elem;
cv::Mat element = cv::getStructuringElement( erosion_type,
cv::Size( 2*erosion_size + 1, 2*erosion_size+1 ),
cv::Point( -1, -1 ) );
cv::Mat srcCV;
srcCV = to_cvmat<unsigned char>(src);
cv::erode( srcCV, dst, element, cv::Point(-1,-1), iterations );
}
void dilateHelper(const cv::Mat& src, cv::Mat& dst, int dilation_elem, int iterations)
{
int dilation_type = 0;
if( dilation_elem == 0 ){ dilation_type = cv::MORPH_RECT; }
else if( dilation_elem == 1 ){ dilation_type = cv::MORPH_CROSS; }
else if( dilation_elem == 2) { dilation_type = cv::MORPH_ELLIPSE; }
int dilation_size = dilation_elem;
cv::Mat element = cv::getStructuringElement( dilation_type,
cv::Size( 2*dilation_size + 1, 2*dilation_size+1 ),
cv::Point( -1, -1 ) );
cv::dilate( src, dst, element, cv::Point(-1,-1), iterations );
}
void findContoursHelper(const cv::Mat& image, std::vector<std::vector<cv::Point>>& contours, int mode, int method)
{
cv::findContours( image, contours, mode, method );
imageIn = Cube<unsigned char>(960, 720, 3);
modImageOut = Cube<unsigned char>(960, 720, 3);
gaussBlur.init();
arm.init();
cvtColor.init();
}
void execute()
{
erodeHelper(src, dst, erosion_elem, iterations);
dilateHelper(dst, dst3, dilation_elem, iterations);
findContoursHelper(dst3, contours);
gaussBlur.src = imageIn;
gaussBlur.sizeX = sizeXIn;
gaussBlur.sizeY = sizeYIn;
gaussBlur.sigmaX = sigmaXIn;
gaussBlur.sigmaY = sigmaYIn;
gaussBlur.execute();
arm.src = gaussBlur.dst;
arm.execute();
cvtColor.src = arm.dst;
cvtColor.colorConversion = colorConversionIn;
cvtColor.execute();
modImageOut = cvtColor.dst;
}
};
......
/* (c) https://github.com/MontiCore/monticore */
package test.math;
component Arma{
port
in Q^{n,m} src,
out Q^{n,m} dst;
implementation Math{
dst = 0.5 * src;
}
}
......@@ -3,18 +3,30 @@ package test.math;
component ErodeAndGaussianBlurCommandTest{
port
in Q^{n,m,3} src,
in Z erosion_elemIn,
in Q^{3} sizeY,
in Q^{2} two,
out Q^{n,m,3} dst,
out Q^{n,m,3} dst3,
out Q^{3,n,m} outMatrix,
out Q^{2,m} out2Matrix;
in Q^{960,720,3} imageIn,
in Z sizeXIn,
in Z sizeYIn,
in Q sigmaXIn,
in Q sigmaYIn,
//CvtColor ports
in Z colorConversionIn,
out Q^{960,720,3} modImageOut;
instance GaussianBlurCommandTest gaussBlur;
instance Arma arm;
instance CvtColorCommandTest cvtColor;
connect imageIn -> gaussBlur.src;
connect sizeXIn -> gaussBlur.sizeX;
connect sizeYIn -> gaussBlur.sizeY;
connect sigmaXIn -> gaussBlur.sigmaX;
connect sigmaYIn -> gaussBlur.sigmaY;
connect gaussBlur.dst -> arm.src;
connect arm.dst -> cvtColor.src;
connect colorConversionIn -> cvtColor.colorConversion;
connect cvtColor.dst -> modImageOut;
//implementation Math{
// dst = erode(src, erosion_elem, iterations);
......
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