Commit 8f53e604 authored by Ahmed's avatar Ahmed

add some changes

parent 12bf3bd9
......@@ -84,8 +84,9 @@ public class LargestContourCommand extends MathCommand {
return new Instruction() {
@Override
public String getTargetLanguageInstruction() {
return "double maxArea = 0;\n" +
"int maxAreaContourId = -1;\n" +
return " std::vector<cv::Point> singleContour;\n" +
" double maxArea = 0;\n" +
" int maxAreaContourId = 0;\n" +
" for (int j = 0; j < contours.size(); j++) {\n" +
" double newArea = cv::contourArea(contours.at(j));\n" +
" if (newArea > maxArea) {\n" +
......@@ -93,7 +94,7 @@ public class LargestContourCommand extends MathCommand {
" maxAreaContourId = j;\n" +
" }\n" +
" }\n" +
" return contours.at(maxAreaContourId);\n";
" return contours.empty()? singleContour: contours.at(maxAreaContourId);\n";
}
@Override
......
......@@ -16,8 +16,9 @@ void init()
}
std::vector<cv::Point> largestContour(const std::vector<std::vector<cv::Point>>& contours)
{
double maxArea = 0;
int maxAreaContourId = -1;
std::vector<cv::Point> singleContour;
double maxArea = 0;
int maxAreaContourId = 0;
for (int j = 0; j < contours.size(); j++) {
double newArea = cv::contourArea(contours.at(j));
if (newArea > maxArea) {
......@@ -25,7 +26,7 @@ int maxAreaContourId = -1;
maxAreaContourId = j;
}
}
return contours.at(maxAreaContourId);
return contours.empty()? singleContour: contours.at(maxAreaContourId);
}
void execute()
{
......
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