48 lines
1.2 KiB
C++
48 lines
1.2 KiB
C++
#include <opencv2/core.hpp>
|
|
#include <opencv2/highgui.hpp>
|
|
#include <opencv2/imgcodecs.hpp>
|
|
#include <opencv2/imgproc.hpp>
|
|
|
|
#include "ImageAnalyzer.hpp"
|
|
#include "FaultManager.hpp"
|
|
|
|
using namespace cv;
|
|
|
|
bool ImageAnalyzer::ProcessImage(uint32_t width, uint32_t height, uint8_t *imgPointer, FaultManager fault_mgr)
|
|
{
|
|
Mat mask;
|
|
std::vector<std::vector<Point>> contours;
|
|
Mat frame(height, width, CV_16UC1, imgPointer, Mat::AUTO_STEP);
|
|
|
|
int temp_threshold = fault_mgr.GetTemp();
|
|
double fault_area = fault_mgr.GetArea();
|
|
|
|
threshold(frame, mask, temp_threshold, temp_threshold, THRESH_BINARY);
|
|
|
|
findContours(mask, contours, RETR_TREE, CHAIN_APPROX_NONE);
|
|
|
|
for(int i = 0; i< contours.size(); i++)
|
|
{
|
|
auto area = contourArea(contours[i]);
|
|
|
|
if (area > fault_area)
|
|
{
|
|
drawContours(frame, contours[i], -1, Scalar(0, 255, 0), 3);
|
|
fault_mgr.SaveImage(frame);
|
|
}
|
|
}
|
|
|
|
//scaled.convertTo(scaled, CV_8UC1);
|
|
//applyColorMap(scaled, color, COLORMAP_JET);
|
|
|
|
namedWindow("FLIR", WINDOW_AUTOSIZE);
|
|
imshow("FLIR", frame);
|
|
|
|
if (waitKey(1) == 27)
|
|
{
|
|
destroyAllWindows();
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
} |