Skip to content
Snippets Groups Projects
Commit 777430aa authored by rohezal's avatar rohezal
Browse files

added stats for NN

parent 497345c4
No related branches found
No related tags found
No related merge requests found
......@@ -3,7 +3,7 @@ project( DisplayImage )
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
SET(CMAKE_CXX_FLAGS "-std=c++11")
SET(CMAKE_CXX_FLAGS "-std=c++17")
file(GLOB CPP_FILES
${PROJECT_SOURCE_DIR}/src/*.cpp
......
......@@ -4,9 +4,12 @@
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
#include <map>
#include <variant>
#include "island.h"
#include "islands.h"
extern float contrastAlpha;// = 5.8f;
extern float contrastBeta;// = -2.8f;
extern float contrastAlpha2;// = 5.6f;
......@@ -32,6 +35,7 @@ cv::Mat calculateHSVContrastImage(cv::Mat img);
cv::Mat matMaxf(cv::Mat a, cv::Mat b);
cv::Mat fillSobel(cv::Mat sobel, cv::Mat contrast);
cv::Mat fillSobelRash(cv::Mat& sobel, cv::Mat& hsvValue);
std::map<std::string,std::variant<int,float,size_t> > getStats(const cv::Mat& islandImage);
std::vector<std::vector<cv::Vec2i>> calculateIslandsAccelerationStructure(const cv::Mat& _image);
......
......@@ -408,8 +408,11 @@ cv::Mat applyCrackFilter2(cv::Mat img, cv::Mat& contrast_image)
temp.convertTo(filledImage,CV_8UC1,255);
//imwrite(filepath+"filled32Bit.png", temp);
//imwrite(filepath+"filled.png", filledImage);
//imwrite(filepath+"filled32Bit.png", temp);
imwrite(filepath+"filled.png", filledImage);
getStats(filledImage);
return filledImage;
}
......@@ -588,3 +591,57 @@ std::vector<std::vector<cv::Vec2i> > calculateIslandsAccelerationStructure(const
}
return acceleration_structure;
}
std::map<std::string, std::variant<int, float, size_t> > getStats(const Mat &islandImage)
{
std::map<std::string, std::variant<int, float, size_t> > stats;
cv::Mat stats_opencv;
cv::Mat labels;
cv::Mat centroids;
cv::connectedComponentsWithStats(islandImage,labels,stats_opencv, centroids);
std::vector<std::size_t> number_of_pixels;
for(size_t i = 0; i < labels.rows; i++)
{
number_of_pixels.push_back(stats_opencv.at<int>(Point(CC_STAT_AREA, i)));
}
const int number_of_islands = labels.rows;
std::sort(number_of_pixels.begin(),number_of_pixels.end());
stats["number_of_islands"] = number_of_islands;
if(number_of_islands > 3)
{
return stats;
}
int median_islands_size = 0;
const int largest_island_size = number_of_pixels.back();
const int large_average_size = (number_of_pixels[number_of_pixels.size()-1] + number_of_pixels[number_of_pixels.size()-2] + number_of_pixels[number_of_pixels.size()-3]) / 3 ;
int small_island_size = large_average_size/100;
int large_island_size = large_average_size/10;
int number_of_small_islands = 0;
int number_of_large_islands = 0;
for(size_t i = 0; i < number_of_pixels.size(); i++)
{
number_of_small_islands += number_of_pixels[i] < small_island_size ? 1 : 0;
number_of_large_islands = number_of_pixels[i] >= large_island_size ? 1 : 0;
}
stats["number_of_large_islands"] = number_of_large_islands;
stats["number_of_small_islands"] = number_of_small_islands;
//number of big islands under each other in y direction
return stats;
}
......@@ -3,7 +3,7 @@
extern char const* title;
void show(cv::Mat image){
return;
return;
cv::namedWindow(title, cv::WINDOW_NORMAL);
cv::imshow(title, image);
//cv::resizeWindow(title, 1000, 1000);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment