Add Socket Support
This commit is contained in:
100
ImageManager.cpp
Normal file
100
ImageManager.cpp
Normal file
@@ -0,0 +1,100 @@
|
||||
#include <opencv2/core.hpp>
|
||||
#include <opencv2/highgui.hpp>
|
||||
#include <opencv2/imgcodecs.hpp>
|
||||
#include <opencv2/imgproc.hpp>
|
||||
|
||||
#include "ImageManager.hpp"
|
||||
#include "FaultManager.hpp"
|
||||
|
||||
#define ZERO 0
|
||||
#define BITS8 0xff
|
||||
#define BITS14 0x3fff
|
||||
#define BITS16 0xffff
|
||||
|
||||
using namespace cv;
|
||||
|
||||
Mat testFrame = imread("/home/midstate/Documents/flirTest.tif", CV_16UC1);
|
||||
|
||||
bool ImageManager::ProcessImage(uint32_t width, uint32_t height, uint8_t *imgPointer, FaultManager fault_mgr, bool test = false)
|
||||
{
|
||||
Mat frame, mask, viewfinder;
|
||||
std::vector<std::vector<Point>> contours;
|
||||
|
||||
static int lower_bound = ZERO;
|
||||
static int upper_bound = BITS14;
|
||||
static int temp_threshold = BITS14;
|
||||
static int fault_area = ZERO;
|
||||
|
||||
if (throttle_count == THROTTLE_AMOUNT)
|
||||
{
|
||||
throttle_count = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
throttle_count++;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Read in frame
|
||||
if (!test)
|
||||
frame = Mat(height, width, CV_16UC1, imgPointer, Mat::AUTO_STEP);
|
||||
else
|
||||
frame = testFrame;
|
||||
|
||||
// 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++)
|
||||
{
|
||||
double area = contourArea(contours[i]);
|
||||
|
||||
if (area > fault_area)
|
||||
{
|
||||
drawContours(viewfinder, contours, i, Scalar(ZERO, BITS8, ZERO), 2);
|
||||
fault_mgr.SaveImage(viewfinder);
|
||||
}
|
||||
}
|
||||
|
||||
// Create Viewfinder Window
|
||||
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);
|
||||
|
||||
if (waitKey(1) == 27 || getWindowProperty("FLIR Viewfinder", WND_PROP_FULLSCREEN) == -1)
|
||||
{
|
||||
destroyAllWindows();
|
||||
return false;
|
||||
}
|
||||
|
||||
// Send image to other servers
|
||||
SendImage(viewfinder);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ImageManager::SendImage(Mat image)
|
||||
{
|
||||
std::vector<uchar> buff;
|
||||
cv::imencode(".jpg", image, buff);
|
||||
|
||||
QByteArray *datagram = new QByteArray(reinterpret_cast<const char*>(buff.data()), buff.size());
|
||||
socket->write(*datagram);
|
||||
}
|
||||
Reference in New Issue
Block a user