Skip to content

Commit cef0c59

Browse files
phurleySamCarlberg
authored andcommitted
Fix issue #744, related to failed code generation with contours (#745)
1 parent 84dc340 commit cef0c59

File tree

7 files changed

+19
-17
lines changed

7 files changed

+19
-17
lines changed

ui/src/main/resources/edu/wpi/grip/ui/codegeneration/cpp/Pipeline.h.vm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
\#include <stdio.h>
1515
\#include <stdlib.h>
1616
\#include <map>
17+
\#include <vector>
18+
\#include <string>
1719
\#include <math.h>
1820

1921
namespace grip {

ui/src/main/resources/edu/wpi/grip/ui/codegeneration/cpp/Pipeline.vm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ $fileName::$fileName() {
3737
#set($outCnt = 0)
3838
#foreach($step in $pipeline.getSteps())
3939
#foreach($out in $step.getOutputs())
40-
outputs.insert(make_pair(string("$out.name().toLowerCase().replaceAll("_", "")"), (AbsPipeline::Output)&$fileName::get${out.name()}));
40+
outputs.insert(make_pair(std::string("$out.name().toLowerCase().replaceAll("_", "")"), (AbsPipeline::Output)&$fileName::get${out.name()}));
4141
#set($outCnt = $outCnt + 1)
4242
#end
4343
#end

ui/src/main/resources/edu/wpi/grip/ui/codegeneration/cpp/macros.vm

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
#macro(cType $type)#if($type.equals("Double") || $type.equals("Number"))
22
double#elseif($type.equals("Object"))
33
void#elseif ($type.equals("ContoursReport"))
4-
vector<vector<Point> >#elseif ($type.equals("BlobsReport"))
5-
vector<KeyPoint>#elseif ($type.equals("LinesReport"))
6-
vector<Line>#elseif ($type.equals("RectsReport"))
7-
vector<Rect>#elseif($type == "Integer" )
4+
std::vector<std::vector<cv::Point> >#elseif ($type.equals("BlobsReport"))
5+
std::vector<cv::KeyPoint>#elseif ($type.equals("LinesReport"))
6+
std::vector<Line>#elseif ($type.equals("RectsReport"))
7+
std::vector<cv::Rect>#elseif($type == "Integer" )
88
int#elseif($type == "Boolean" || "boolean")
99
bool#elseif($type.equals("String"))
10-
string#elseif($type.contains("Enum"))
10+
std::string#elseif($type.contains("Enum"))
1111
int#elseif($type.equalsIgnoreCase("BlurType"))
1212
BlurType#elseif($type.contains("Type"))
1313
int#elseif($type.equalsIgnoreCase("MaskSize"))
14-
string#elseif($type.equalsIgnoreCase("Interpolation"))
14+
std::string#elseif($type.equalsIgnoreCase("Interpolation"))
1515
int#elseif($type.equalsIgnoreCase("FlipCode"))
1616
FlipCode#elseif($type.equalsIgnoreCase("List"))
1717
List#else
1818
cv::$type#end#end
1919

2020
#macro(funPassType $baseType)
2121
#set($type = "#cType($baseType)")
22-
#if($type.equals("double") || $type.equals("int") || $type.equals("bool") || $type.equals("string"))
22+
#if($type.equals("double") || $type.equals("int") || $type.equals("bool") || $type.equals("std::string"))
2323
#else
2424
&#end#end
2525

@@ -67,13 +67,13 @@ $name(#foreach($inp in $step.getInputs())#param($inp $names[$count])#set($count
6767
#elseif ($input.type().contains("Enum"))
6868
int ${tMeth.name($input.name())} = $input.value(); // ENUM $input.type()
6969
#elseif ($input.type().equals("MaskSize") )
70-
string ${tMeth.name($input.name())} = "$input.value()";
70+
std::string ${tMeth.name($input.name())} = "$input.value()";
7171
#elseif ($input.type().equals("FlipCode") || $input.type().equals("BlurType") )
7272
$input.type() ${tMeth.name($input.name())} = $input.type()::#cvVal($input.value());
7373
#elseif ($input.type().contains("Type") || $input.type().equals("Interpolation"))
7474
int ${tMeth.name($input.name())} = #cvVal($input.value());
7575
#elseif ($input.type().equals("String"))
76-
string ${tMeth.name($input.name())} = "$input.value()";
76+
std::string ${tMeth.name($input.name())} = "$input.value()";
7777
#elseif ($input.type().equals("List"))
7878
#set($inputEndValue = $input.value().length() - 1)
7979
double ${tMeth.name($input.name())}[] = {$input.value().substring(1,$inputEndValue)};

ui/src/main/resources/edu/wpi/grip/ui/codegeneration/cpp/operations/Convex_Hulls.vm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
* @param outputContours The contours where the output will be stored.
66
*/
77
void $fileName::#func($step, ["inputContours", "outputContours"]) {
8-
std::vector<vector<cv::Point> > hull (inputContours.size());
8+
std::vector<std::vector<cv::Point> > hull (inputContours.size());
99
outputContours.clear();
10-
for (int i = 0; i < inputContours.size(); i++ ) {
10+
for (size_t i = 0; i < inputContours.size(); i++ ) {
1111
cv::convexHull(cv::Mat((inputContours)[i]), hull[i], false);
1212
}
1313
outputContours = hull;

ui/src/main/resources/edu/wpi/grip/ui/codegeneration/cpp/operations/Filter_Contours.vm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ This creates the C++ OpenCV Filter Contours function
2020
void $fileName::#func($step ["inputContours", "minArea", "minPerimeter", "minWidth", "maxWidth", "minHeight", "maxHeight", "solidity", "maxVertexCount", "minVertexCount", "minRatio", "maxRatio", "output"]) {
2121
std::vector<cv::Point> hull;
2222
output.clear();
23-
for (std::vector<Point> contour: inputContours) {
23+
for (std::vector<cv::Point> contour: inputContours) {
2424
cv::Rect bb = boundingRect(contour);
2525
if (bb.width < minWidth || bb.width > maxWidth) continue;
2626
if (bb.height < minHeight || bb.height > maxHeight) continue;
2727
double area = cv::contourArea(contour);
2828
if (area < minArea) continue;
2929
if (arcLength(contour, true) < minPerimeter) continue;
30-
cv::convexHull(Mat(contour, true), hull);
30+
cv::convexHull(cv::Mat(contour, true), hull);
3131
double solid = 100 * area / cv::contourArea(hull);
3232
if (solid < solidity[0] || solid > solidity[1]) continue;
3333
if (contour.size() < minVertexCount || contour.size() > maxVertexCount) continue;

ui/src/main/resources/edu/wpi/grip/ui/codegeneration/cpp/operations/Filter_Lines.vm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99
void $fileName::#func($step ["inputs", "minLength", "angle", "outputs"]) {
1010
outputs.clear();
11-
for (cv::Line line: inputs) {
11+
for (Line line: inputs) {
1212
if (line.length()>abs(minLength)) {
1313
if ((line.angle() >= angle[0] && line.angle() <= angle[1]) ||
1414
(line.angle() + 180.0 >= angle[0] && line.angle() + 180.0 <=angle[1])) {

ui/src/main/resources/edu/wpi/grip/ui/codegeneration/cpp/operations/Find_Contours.vm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
void $fileName::#func($step ["input", "externalOnly", "contours"]) {
99
std::vector<cv::Vec4i> hierarchy;
1010
contours.clear();
11-
int mode = externalOnly ? RETR_EXTERNAL : RETR_LIST;
12-
int method = CHAIN_APPROX_SIMPLE;
11+
int mode = externalOnly ? cv::RETR_EXTERNAL : cv::RETR_LIST;
12+
int method = cv::CHAIN_APPROX_SIMPLE;
1313
cv::findContours(input, contours, hierarchy, mode, method);
1414
}

0 commit comments

Comments
 (0)