Add Image Manager Code
This commit is contained in:
@@ -1,13 +1,93 @@
|
|||||||
#include <QDBusConnection>
|
#include <opencv2/core.hpp>
|
||||||
#include <QDebug>
|
#include <opencv2/highgui.hpp>
|
||||||
|
#include <opencv2/imgcodecs.hpp>
|
||||||
|
#include <opencv2/imgproc.hpp>
|
||||||
|
|
||||||
#include "ImageManager.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);
|
||||||
|
|
||||||
ImageManager::ImageManager(QObject *parent) : QObject(parent)
|
ImageManager::ImageManager(QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
|
socket = new QUdpSocket();
|
||||||
|
socket->connectToHost(QHostAddress::LocalHost, 40000, QIODevice::ReadWrite);
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageManager::~ImageManager()
|
ImageManager::~ImageManager()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ImageManager::ProcessImage(uint32_t width, uint32_t height, uint8_t *imgPointer)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
//parent->fault_mgr.SaveImage(frame);
|
||||||
|
//((FaultFinder*)(parent()))->fault_mgr.SaveImage(frame);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send image to other servers
|
||||||
|
SendImage(viewfinder);}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
@@ -2,16 +2,27 @@
|
|||||||
#define IMAGE_MANAGER_H
|
#define IMAGE_MANAGER_H
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
#include <QUdpSocket>
|
||||||
|
#include <opencv2/core.hpp>
|
||||||
|
|
||||||
|
#define THROTTLE_AMOUNT 1
|
||||||
|
|
||||||
class ImageManager: public QObject
|
class ImageManager: public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT;
|
Q_OBJECT;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
ImageManager(QObject *parent);
|
ImageManager(QObject *parent);
|
||||||
virtual ~ImageManager();
|
virtual ~ImageManager();
|
||||||
|
|
||||||
|
void ProcessImage(uint32_t width, uint32_t height, uint8_t *imgPointer);
|
||||||
|
void SendImage(cv::Mat image);
|
||||||
|
|
||||||
|
QUdpSocket *socket;
|
||||||
|
|
||||||
|
private:
|
||||||
|
int throttle_count = 1;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
Reference in New Issue
Block a user