Add Test Mode and Viewfinder
This commit is contained in:
2
.vscode/launch.json
vendored
2
.vscode/launch.json
vendored
@@ -9,7 +9,7 @@
|
|||||||
"type": "cppdbg",
|
"type": "cppdbg",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"program": "${workspaceFolder}/FaultFinder",
|
"program": "${workspaceFolder}/FaultFinder",
|
||||||
"args": [],
|
"args": ["test"],
|
||||||
"stopAtEntry": false,
|
"stopAtEntry": false,
|
||||||
"cwd": "${workspaceFolder}",
|
"cwd": "${workspaceFolder}",
|
||||||
"environment": [],
|
"environment": [],
|
||||||
|
|||||||
@@ -10,8 +10,19 @@ int main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
StreamManager stream_mgr;
|
StreamManager stream_mgr;
|
||||||
ImageAnalyzer analyzer;
|
ImageAnalyzer analyzer;
|
||||||
FaultManager fault_mgr(stoi(argv[1]), stod(argv[2]));
|
FaultManager fault_mgr;
|
||||||
PvString lConnectionID;
|
PvString lConnectionID;
|
||||||
|
|
||||||
|
// If running in test mode
|
||||||
|
if (argc > 1 && !strcmp(argv[1], "test"))
|
||||||
|
{
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
if (!analyzer.ProcessImage(0, 0, 0, fault_mgr, true))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// If no devies are found, exit.
|
// If no devies are found, exit.
|
||||||
if (stream_mgr.FindDevice(&lConnectionID).IsFailure())
|
if (stream_mgr.FindDevice(&lConnectionID).IsFailure())
|
||||||
|
|||||||
@@ -7,15 +7,5 @@ using namespace cv;
|
|||||||
void FaultManager::SaveImage(Mat image)
|
void FaultManager::SaveImage(Mat image)
|
||||||
{
|
{
|
||||||
// Tag date, time, gps in file meta data
|
// Tag date, time, gps in file meta data
|
||||||
imwrite( "/tmp/uniquetime.png", image);
|
//imwrite( "/tmp/uniquetime.png", image);
|
||||||
}
|
|
||||||
|
|
||||||
int FaultManager::GetTemp()
|
|
||||||
{
|
|
||||||
return temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
double FaultManager::GetArea()
|
|
||||||
{
|
|
||||||
return area;
|
|
||||||
}
|
}
|
||||||
@@ -8,23 +8,8 @@ class FaultManager
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
FaultManager(int temp, double area)
|
|
||||||
{
|
|
||||||
if (temp)
|
|
||||||
temp = temp;
|
|
||||||
if (area)
|
|
||||||
area = area;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SaveImage(cv::Mat image);
|
void SaveImage(cv::Mat image);
|
||||||
|
|
||||||
int GetTemp();
|
|
||||||
double GetArea();
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
int temp = 100;
|
|
||||||
double area = 100;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -6,39 +6,67 @@
|
|||||||
#include "ImageAnalyzer.hpp"
|
#include "ImageAnalyzer.hpp"
|
||||||
#include "FaultManager.hpp"
|
#include "FaultManager.hpp"
|
||||||
|
|
||||||
|
#define ZERO 0
|
||||||
|
#define BITS8 0xff
|
||||||
|
#define BITS14 0x3fff
|
||||||
|
#define BITS16 0xffff
|
||||||
|
|
||||||
using namespace cv;
|
using namespace cv;
|
||||||
|
|
||||||
bool ImageAnalyzer::ProcessImage(uint32_t width, uint32_t height, uint8_t *imgPointer, FaultManager fault_mgr)
|
bool ImageAnalyzer::ProcessImage(uint32_t width, uint32_t height, uint8_t *imgPointer, FaultManager fault_mgr, bool test = false)
|
||||||
{
|
{
|
||||||
Mat mask;
|
Mat frame, mask, viewfinder;
|
||||||
std::vector<std::vector<Point>> contours;
|
std::vector<std::vector<Point>> contours;
|
||||||
Mat frame(height, width, CV_16UC1, imgPointer, Mat::AUTO_STEP);
|
|
||||||
|
|
||||||
int temp_threshold = fault_mgr.GetTemp();
|
static int lower_bound = ZERO;
|
||||||
double fault_area = fault_mgr.GetArea();
|
static int upper_bound = BITS14;
|
||||||
|
static int temp_threshold = BITS14;
|
||||||
|
static int fault_area = ZERO;
|
||||||
|
|
||||||
threshold(frame, mask, temp_threshold, temp_threshold, THRESH_BINARY);
|
// Read in frame
|
||||||
|
if (!test)
|
||||||
|
frame = Mat(height, width, CV_16UC1, imgPointer, Mat::AUTO_STEP);
|
||||||
|
else
|
||||||
|
frame = imread("/home/midstate/Documents/image.png", CV_16UC1);
|
||||||
|
|
||||||
findContours(mask, contours, RETR_TREE, CHAIN_APPROX_NONE);
|
// Create mask and then flatten
|
||||||
|
GaussianBlur(frame, mask, cv::Size(0, 0), 1);
|
||||||
|
threshold(mask, mask, temp_threshold, BITS16, THRESH_BINARY); // use inrange for mask in range of values
|
||||||
|
mask.convertTo(mask, CV_8UC1);
|
||||||
|
|
||||||
|
// Analyze mask
|
||||||
|
findContours(mask, contours, RETR_EXTERNAL, CHAIN_APPROX_NONE);
|
||||||
|
|
||||||
|
// Create viewfinder with results
|
||||||
|
viewfinder = frame.clone();
|
||||||
|
viewfinder.setTo(lower_bound, viewfinder < lower_bound);
|
||||||
|
viewfinder.setTo(upper_bound, viewfinder > upper_bound);
|
||||||
|
normalize(viewfinder, viewfinder, ZERO, BITS8, NORM_MINMAX, CV_8UC1);
|
||||||
|
applyColorMap(viewfinder, viewfinder, COLORMAP_HOT);
|
||||||
|
|
||||||
|
// Apply contours to viewfinder
|
||||||
for(int i = 0; i< contours.size(); i++)
|
for(int i = 0; i< contours.size(); i++)
|
||||||
{
|
{
|
||||||
auto area = contourArea(contours[i]);
|
double area = contourArea(contours[i]);
|
||||||
|
|
||||||
if (area > fault_area)
|
if (area > fault_area)
|
||||||
{
|
{
|
||||||
drawContours(frame, contours[i], -1, Scalar(0, 255, 0), 3);
|
drawContours(viewfinder, contours, i, Scalar(ZERO, BITS8, ZERO), 2);
|
||||||
fault_mgr.SaveImage(frame);
|
fault_mgr.SaveImage(frame);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//scaled.convertTo(scaled, CV_8UC1);
|
// Create Viewfinder Window
|
||||||
//applyColorMap(scaled, color, COLORMAP_JET);
|
createTrackbar("Lower Bound", "FLIR Viewfinder", &lower_bound, BITS14, NULL);
|
||||||
|
createTrackbar("Upper Bound", "FLIR Viewfinder", &upper_bound, BITS14, NULL);
|
||||||
|
createTrackbar("Temperature Threshold", "FLIR Viewfinder", &temp_threshold, BITS14, NULL);
|
||||||
|
createTrackbar("Fault Area", "FLIR Viewfinder", &fault_area, 0x50280, NULL);
|
||||||
|
// Make clicking a pixel display the temp value
|
||||||
|
//setMouseCallback("FLIR Viewfinder", NULL);
|
||||||
|
namedWindow("FLIR Viewfinder", WINDOW_AUTOSIZE);
|
||||||
|
imshow("FLIR Viewfinder", viewfinder);
|
||||||
|
|
||||||
namedWindow("FLIR", WINDOW_AUTOSIZE);
|
if (waitKey(1) == 27 || getWindowProperty("FLIR Viewfinder", WND_PROP_FULLSCREEN) == -1)
|
||||||
imshow("FLIR", frame);
|
|
||||||
|
|
||||||
if (waitKey(1) == 27)
|
|
||||||
{
|
{
|
||||||
destroyAllWindows();
|
destroyAllWindows();
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ class ImageAnalyzer
|
|||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
bool ProcessImage(uint32_t width, uint32_t height, uint8_t *imgPointer, FaultManager fault_mgr);
|
bool ProcessImage(uint32_t width, uint32_t height, uint8_t *imgPointer, FaultManager fault_mgr, bool test);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -196,7 +196,7 @@ void StreamManager::AcquireImages(ImageAnalyzer analyzer, FaultManager fault_mgr
|
|||||||
lHeight = lImage->GetHeight();
|
lHeight = lImage->GetHeight();
|
||||||
|
|
||||||
// Process Image
|
// Process Image
|
||||||
if (!analyzer.ProcessImage(lWidth, lHeight, lImage->GetDataPointer(), fault_mgr))
|
if (!analyzer.ProcessImage(lWidth, lHeight, lImage->GetDataPointer(), fault_mgr, false))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
std::cout << " W: " << std::dec << lWidth << " H: " << lHeight;
|
std::cout << " W: " << std::dec << lWidth << " H: " << lHeight;
|
||||||
|
|||||||
Reference in New Issue
Block a user