Add ImageManager

This commit is contained in:
Grant Terris
2019-09-02 18:01:06 -07:00
parent 5ea03a6a0c
commit 8c7d4c0b43
10 changed files with 136 additions and 69 deletions

View File

@@ -14,7 +14,8 @@ include_directories(
add_executable( FaultFinder
FaultFinder.cpp
StreamManager.cpp
ImageProcessor.cpp
ImageAnalyzer.cpp
FaultManager.cpp
)
target_link_libraries( FaultFinder

View File

@@ -1,32 +1,34 @@
#include <iostream>
#include "StreamManager.hpp"
#include "ImageProcessor.hpp"
#include "ImageAnalyzer.hpp"
#include "FaultManager.hpp"
using namespace std;
int main()
int main(int argc, char **argv)
{
ImageProcessor processor;
StreamManager manager;
StreamManager stream_mgr;
ImageAnalyzer analyzer;
FaultManager fault_mgr(stoi(argv[1]), stod(argv[2]));
PvString lConnectionID;
// If no devies are found, exit.
if (manager.FindDevice(&lConnectionID).IsFailure())
{
return -1;
}
if (manager.ConnectToDevice(lConnectionID).IsFailure())
{
return -1;
}
manager.OpenStream(lConnectionID);
manager.AcquireImages(processor);
// If no devies are found, exit.
if (stream_mgr.FindDevice(&lConnectionID).IsFailure())
{
return -1;
}
manager.Disconnect();
if (stream_mgr.ConnectToDevice(lConnectionID).IsFailure())
{
return -1;
}
stream_mgr.OpenStream(lConnectionID);
stream_mgr.AcquireImages(analyzer, fault_mgr);
stream_mgr.Disconnect();
return 0;
}

21
FaultManager.cpp Normal file
View File

@@ -0,0 +1,21 @@
#include <opencv2/opencv.hpp>
#include "FaultManager.hpp"
using namespace cv;
void FaultManager::SaveImage(Mat image)
{
// Tag date, time, gps in file meta data
imwrite( "/tmp/uniquetime.png", image);
}
int FaultManager::GetTemp()
{
return temp;
}
double FaultManager::GetArea()
{
return area;
}

30
FaultManager.hpp Normal file
View File

@@ -0,0 +1,30 @@
#ifndef FAULTMANAGER_H
#define FAULTMANAGER_H
#include <opencv2/core.hpp>
class FaultManager
{
public:
FaultManager(int temp, double area)
{
if (temp)
temp = temp;
if (area)
area = area;
}
void SaveImage(cv::Mat image);
int GetTemp();
double GetArea();
private:
int temp = 100;
double area = 100;
};
#endif

View File

@@ -0,0 +1,48 @@
#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;
}

View File

@@ -1,9 +1,16 @@
#ifndef IMAGEANALYZER_H
#define IMAGEANALYZER_H
#include <opencv2/core.hpp>
#include "FaultManager.hpp"
class ImageAnalyzer
{
public:
bool ProcessImage(uint32_t width, uint32_t height, uint8_t *imgPointer, FaultManager fault_mgr);
};
#endif

View File

@@ -1,25 +0,0 @@
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/imgproc.hpp>
#include "ImageProcessor.hpp"
using namespace cv;
void ImageProcessor::ProcessImage(uint32_t width, uint32_t height, uint8_t *imgPointer)
{
Mat frame(height, width, CV_16U, imgPointer, Mat::AUTO_STEP);
//normalize(frame, scaled, 0, 255, NORM_MINMAX);
//scaled.convertTo(scaled, CV_8UC1);
//applyColorMap(scaled, color, COLORMAP_JET);
//namedWindow("FLIR", WINDOW_AUTOSIZE);
//imshow("FLIR", color);
int key = waitKey(1);
//if key == 27, then break
//release()
//destroyAllWindows()
}

View File

@@ -1,15 +0,0 @@
#ifndef IMAGEPROCESSOR_H
#define IMAGEPROCESSOR_H
#include <opencv2/core.hpp>
class ImageProcessor
{
public:
void ProcessImage(uint32_t width, uint32_t height, uint8_t *imgPointer);
};
#endif

View File

@@ -7,6 +7,7 @@
#include <PvStreamGEV.h>
#include "StreamManager.hpp"
#include "FaultManager.hpp"
PvResult StreamManager::FindDevice(PvString *aConnectionID)
{
@@ -133,7 +134,7 @@ void StreamManager::CreateStreamBuffers()
}
}
void StreamManager::AcquireImages(ImageProcessor processor)
void StreamManager::AcquireImages(ImageAnalyzer analyzer, FaultManager fault_mgr)
{
if (lDevice == NULL || lStream == NULL)
{
@@ -178,11 +179,6 @@ void StreamManager::AcquireImages(ImageProcessor processor)
{
PvPayloadType lType;
//
// We now have a valid buffer. This is where you would typically process the buffer.
// -----------------------------------------------------------------------------------------
// ...
lFrameRate->GetValue(lFrameRateVal);
lBandwidth->GetValue(lBandwidthVal);
@@ -200,7 +196,8 @@ void StreamManager::AcquireImages(ImageProcessor processor)
lHeight = lImage->GetHeight();
// Process Image
processor.ProcessImage(lWidth, lHeight, lImage->GetDataPointer());
if (!analyzer.ProcessImage(lWidth, lHeight, lImage->GetDataPointer(), fault_mgr))
break;
std::cout << " W: " << std::dec << lWidth << " H: " << lHeight;
}

View File

@@ -4,7 +4,8 @@
#include <PvStream.h>
#include <PvBuffer.h>
#include "ImageProcessor.hpp"
#include "ImageAnalyzer.hpp"
#include "FaultManager.hpp"
#define BUFFER_COUNT (32)
typedef std::list<PvBuffer *> BufferList;
@@ -17,7 +18,7 @@ public:
PvResult FindDevice(PvString *aConnectionID);
PvResult ConnectToDevice(const PvString &aConnectionID);
PvResult OpenStream(const PvString &aConnectionID);
void AcquireImages(ImageProcessor processor);
void AcquireImages(ImageAnalyzer analyzer, FaultManager fault_mgr);
void Disconnect();
private: