Initial commit
This commit is contained in:
74
src/imagepipeline.cpp
Normal file
74
src/imagepipeline.cpp
Normal file
@ -0,0 +1,74 @@
|
||||
#include "imagepipeline.h"
|
||||
#include <uvosunwrap/unwrap.h>
|
||||
#include <QtConcurrent/QtConcurrentRun>
|
||||
#include <QFuture>
|
||||
|
||||
ImagePipeline::ImagePipeline(Cameras* cameras, QObject *parent): QObject(parent), cameras_(cameras)
|
||||
{
|
||||
}
|
||||
|
||||
cv::Mat ImagePipeline::process(const Profile profile, std::vector<Camera::Image> images)
|
||||
{
|
||||
std::vector<RemapedImage> remapedImages;
|
||||
remapedImages.reserve(images.size());
|
||||
|
||||
for(Camera::Image& image : images)
|
||||
{
|
||||
for(auto& camera : profile.cameras)
|
||||
{
|
||||
if(camera.id == image.cameraId)
|
||||
{
|
||||
if(camera.darkmap.data)
|
||||
image.mat = image.mat - camera.darkmap;
|
||||
remapedImages.push_back(applyRemap(image.mat, camera.remapMap));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cv::Mat output = simpleStich(remapedImages);
|
||||
output.convertTo(output, CV_32FC1, 1.0/255.0, 0);
|
||||
|
||||
if(profile.lightmap.data)
|
||||
normalize(output, profile.lightmap);
|
||||
return output;
|
||||
}
|
||||
|
||||
void ImagePipeline::apply(std::vector<Camera::Image> images)
|
||||
{
|
||||
if(!invalid_)
|
||||
{
|
||||
futureImageWatchers_.push_back(new QFutureWatcher<cv::Mat>());
|
||||
connect(futureImageWatchers_.back(), &QFutureWatcher<cv::Mat>::finished, this, &ImagePipeline::imageFinished);
|
||||
|
||||
QFuture<cv::Mat> futureImage = QtConcurrent::run(&ImagePipeline::process, profile_, images);
|
||||
futureImageWatchers_.back()->setFuture(futureImage);
|
||||
}
|
||||
}
|
||||
|
||||
void ImagePipeline::setProfile(const Profile& profile)
|
||||
{
|
||||
profile_ = profile;
|
||||
cameras_->setExposureTime(profile_.exposureTime);
|
||||
cameras_->setLighting(profile_.lighting);
|
||||
if(!profile_.camerasSufficant(cameras_->getCameras()))
|
||||
{
|
||||
invalid_ = true;
|
||||
sigInvalidProfile("A camera required for this profile is not available");
|
||||
}
|
||||
}
|
||||
|
||||
void ImagePipeline::imageFinished()
|
||||
{
|
||||
for(size_t i = 0; i < futureImageWatchers_.size(); ++i)
|
||||
{
|
||||
if(futureImageWatchers_[i]->isFinished())
|
||||
{
|
||||
cv::Mat result = futureImageWatchers_[i]->result();
|
||||
sigResult(Camera::Image(result, 0));
|
||||
delete futureImageWatchers_[i];
|
||||
futureImageWatchers_.erase(futureImageWatchers_.begin()+i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user