Skip to content

Commit

Permalink
feat(CameraEngine.h/.cpp, cameras/): new features.
Browse files Browse the repository at this point in the history
1. new coding stripe cropping function added.
2. the Save Point Cloud feature will save both texture and depth maps simultaneously.
  • Loading branch information
Practice3DVision committed Apr 1, 2024
1 parent 3144550 commit edd2ea2
Show file tree
Hide file tree
Showing 11 changed files with 601 additions and 421 deletions.
6 changes: 3 additions & 3 deletions gui/qml/res/config/binocularCameraConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@
"type" : "number"
},
{
"data" : 32.0,
"data" : 64.0,
"title" : "Cycles",
"type" : "number"
},
{
"data" : 18.0,
"data" : 19.0,
"title" : "Total Fringes",
"type" : "number"
},
Expand Down Expand Up @@ -106,7 +106,7 @@
"type" : "bool"
},
{
"data" : 1,
"data" : 0,
"title" : "Gpu Accelerate",
"type" : "bool"
},
Expand Down
2 changes: 1 addition & 1 deletion gui/qml/res/config/monocularCameraConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"type" : "bool"
},
{
"data" : 1,
"data" : 0,
"title" : "Gpu Accelerate",
"type" : "bool"
},
Expand Down
6 changes: 6 additions & 0 deletions gui/qml/ui/global/Lang.qml
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ QtObject {
property string height
property string length
property string inverse
property string clip_width
property string clip_height

function zh() {
settings = "设置";
Expand Down Expand Up @@ -515,6 +517,8 @@ QtObject {
height = "高度";
length = "长度";
inverse = "翻转特征方向";
clip_width = "裁剪宽度";
clip_height = "裁剪高度";
}

function en() {
Expand Down Expand Up @@ -566,6 +570,8 @@ QtObject {
error_diffusion_method = "Error Diffusion Method";
img_width = "IMG Width";
img_height = "IMG Height";
clip_width = "Clip Width";
clip_height = "Clip Height";
cycles = "Cycles";
shift_time = "Shift Time";
stripe_img = "Stripe IMG";
Expand Down
40 changes: 39 additions & 1 deletion gui/qml/ui/page/Page_Device.qml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ FluContentPage{
property int defocus_encoding: pixel_depth ? AppType.Disable : AppType.OptimalPlusWithModulation
property int img_width: Number(CameraEngine.getStringAttribute("DLP Width"))
property int img_height: Number(CameraEngine.getStringAttribute("DLP Height"))
property int clip_width: img_width
property int clip_height: img_height
property int cycles: CameraEngine.getNumberAttribute("Cycles")
property int shiftTime: CameraEngine.getNumberAttribute("Phase Shift Times")
property int connect_state : AppType.Disconnect
Expand Down Expand Up @@ -688,6 +690,42 @@ FluContentPage{
}
}

FluText {
Layout.fillWidth: true
text: Lang.clip_width
font: FluTextStyle.BodyStrong
}

FluText {
Layout.fillWidth: true
text: Lang.clip_height
font: FluTextStyle.BodyStrong
}

FluSpinBox {
id: clip_width_spbox
editable: true
value: root.clip_width
from: 0
to: 9999999

onValueChanged: {
root.clip_width = value;
}
}

FluSpinBox {
id: clip_height_spbox
editable: true
value: root.clip_height
from: 0
to: 9999999

onValueChanged: {
root.clip_height = value;
}
}

FluText {
Layout.fillWidth: true
text: Lang.cycles
Expand Down Expand Up @@ -763,7 +801,7 @@ FluContentPage{
text: Lang.encode

onClicked: {
var num_of_stripes = CameraEngine.createStripe(root.pixel_depth, root.stripe_direction, root.stripe_type, root.defocus_encoding, root.img_width, root.img_height, root.cycles, root.shiftTime, root.isKeepAdd);
var num_of_stripes = CameraEngine.createStripe(root.pixel_depth, root.stripe_direction, root.stripe_type, root.defocus_encoding, root.img_width, root.img_height, root.clip_width, root.clip_height, root.cycles, root.shiftTime, root.isKeepAdd);
stripe_index_indicator.pageCurrent = 1;
CameraEngine.displayStripe(1);
root.enableBurningStripe = true;
Expand Down
1 change: 1 addition & 0 deletions gui/qml/ui/page/Page_Scan.qml
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,7 @@ FluContentPage {

onAccepted: {
VTKProcessEngine.saveCloud(currentFile.toString());
CameraEngine.saveFrame(currentFile.toString());
}
}

Expand Down
24 changes: 21 additions & 3 deletions gui/src/CameraEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ CameraEngine::~CameraEngine() {
int CameraEngine::createStripe(const int pixelDepth, const int direction,
const int stripeType, const int defocusMethod,
const int imgWidth, const int imgHeight,
const int clipWidth, const int clipHeight,
const int cycles, const int shiftTime,
const bool isKeepAdd) {
qInfo() << "start create stripe...";
Expand Down Expand Up @@ -99,18 +100,24 @@ int CameraEngine::createStripe(const int pixelDepth, const int direction,
AppType::DefocusEncoding(defocusMethod));
}

if(clipWidth < imgWidth || clipHeight < imgHeight) {
for (auto& img : imgs) {
img(cv::Rect(0, 0, clipWidth, clipHeight)).copyTo(img);
}
}

auto formatType =
AppType::PixelDepth(pixelDepth) == AppType::PixelDepth::OneBit
? QImage::Format_Mono
: QImage::Format_Grayscale8;

std::vector<QImage> tempStripes(imgs.size(),
QImage(imgWidth, imgHeight, formatType));
QImage(clipWidth, clipHeight, formatType));
cv::parallel_for_(cv::Range(0, imgs.size()), [&](const cv::Range &range) {
for (int i = range.start; i < range.end; ++i) {
for (int j = 0; j < imgHeight; ++j) {
for (int j = 0; j < clipHeight; ++j) {
auto imgPtr = imgs[i].ptr(j);
for (int k = 0; k < imgWidth; ++k) {
for (int k = 0; k < clipWidth; ++k) {
formatType == QImage::Format_Mono
? tempStripes[i].setPixel(k, j, imgPtr[k])
: tempStripes[i].setPixel(
Expand Down Expand Up @@ -966,3 +973,14 @@ void CameraEngine::tenLine() {

workThread_ = std::thread(&CameraEngine::createTenLine, this);
}

bool CameraEngine::saveFrame(const QString& path) {
auto fileName = path.mid(8, path.size() - 12);

qDebug() << QString("save frame, frame path is : %s").arg(fileName);

cv::imwrite(fileName.toStdString() + ".bmp", frame_.textureMap_);
cv::imwrite(fileName.toStdString() + ".tiff", frame_.depthMap_);

return true;
}
118 changes: 77 additions & 41 deletions gui/src/CameraEngine.h
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
/**
* @file CameraEngine.h
* @author Evans Liu (1369215984@qq.com)
* @brief
* @brief
* @version 0.1
* @date 2024-03-19
*
*
* @copyright Copyright (c) 2024
*
*
*/

#ifndef __CAMERA_ENGINE_H_
#define __CAMERA_ENGINE_H_

#include <vector>
#include <thread>
#include <vector>


#include <QObject>
#include <QThread>

#include <opencv2/opencv.hpp>

#include "AppType.h"
#include "CameraModel.h"
#include "ImagePaintItem.h"
#include "typeDef.h"
#include "CameraModel.h"


#include <slmaster.h>

Expand All @@ -33,28 +35,42 @@ class CameraEngine : public QObject {
Q_PROPERTY_AUTO(bool, isConnected)
Q_PROPERTY_AUTO(bool, isBurnWorkFinish)
public:
static CameraEngine* instance();
static CameraEngine *instance();
struct OrderTableRecord {
OrderTableRecord() {}
OrderTableRecord(const int patternsNum, const int shiftTime, const bool isVertical) : patternsNum_(patternsNum), shiftTime_(shiftTime), isVertical_(isVertical) {}
OrderTableRecord(const int patternsNum, const int shiftTime,
const bool isVertical)
: patternsNum_(patternsNum), shiftTime_(shiftTime),
isVertical_(isVertical) {}
int patternsNum_;
int shiftTime_;
bool isVertical_;
};
//Device page
// Device page
Q_INVOKABLE void startDetectCameraState();
Q_INVOKABLE int createStripe(const int pixelDepth, const int direction, const int stripeType, const int defocusMethod, const int imgWidth, const int imgHeight, const int cycles, const int shiftTime, const bool isKeepAdd);
Q_INVOKABLE int createStripe(const int pixelDepth, const int direction,
const int stripeType, const int defocusMethod,
const int imgWidth, const int imgHeight,
const int clipWidth, const int clipHeight,
const int cycles, const int shiftTime,
const bool isKeepAdd);
Q_INVOKABLE void displayStripe(const int stripeIndex);
Q_INVOKABLE void selectCamera(const int cameraType);
Q_INVOKABLE void setCameraJsonPath(const std::string jsonPath);
Q_INVOKABLE bool connectCamera();
Q_INVOKABLE bool disConnectCamera();
Q_INVOKABLE void burnStripe();
Q_INVOKABLE void bindStripePaintItem(ImagePaintItem* stripePaintItem) { stripePaintItem_ = stripePaintItem; }
//offlineScan page
Q_INVOKABLE void bindOfflineCamPaintItem(ImagePaintItem* camPaintItem) { offlineCamPaintItem_ = camPaintItem; }
//scan page
Q_INVOKABLE void setScanMode(const int scanMode) { scanMode_ = AppType::ScanModeType(scanMode); }
Q_INVOKABLE void bindStripePaintItem(ImagePaintItem *stripePaintItem) {
stripePaintItem_ = stripePaintItem;
}
// offlineScan page
Q_INVOKABLE void bindOfflineCamPaintItem(ImagePaintItem *camPaintItem) {
offlineCamPaintItem_ = camPaintItem;
}
// scan page
Q_INVOKABLE void setScanMode(const int scanMode) {
scanMode_ = AppType::ScanModeType(scanMode);
}
Q_INVOKABLE void projectOnce();
Q_INVOKABLE void projectContinues();
Q_INVOKABLE void pauseProject(const bool isResume);
Expand All @@ -64,50 +80,70 @@ class CameraEngine : public QObject {
Q_INVOKABLE void startScan();
Q_INVOKABLE void continuesScan();
Q_INVOKABLE void pauseScan();
Q_INVOKABLE void bindOfflineLeftCamModel(CameraModel* model) { leftCamModel_ = model; }
Q_INVOKABLE void bindOfflineRightCamModel(CameraModel* model) { rightCamModel_ = model; }
Q_INVOKABLE void bindOfflineColorCamModel(CameraModel* model) { colorCamModel_ = model; }
Q_INVOKABLE void bindScanTexturePaintItem(ImagePaintItem* paintItem) { scanTexturePaintItem_ = paintItem; }
Q_INVOKABLE void updateDisplayImg(const QString& imgPath);
Q_INVOKABLE void saveStripe(const QString& path);
Q_INVOKABLE void bindOfflineLeftCamModel(CameraModel *model) {
leftCamModel_ = model;
}
Q_INVOKABLE void bindOfflineRightCamModel(CameraModel *model) {
rightCamModel_ = model;
}
Q_INVOKABLE void bindOfflineColorCamModel(CameraModel *model) {
colorCamModel_ = model;
}
Q_INVOKABLE void bindScanTexturePaintItem(ImagePaintItem *paintItem) {
scanTexturePaintItem_ = paintItem;
}
Q_INVOKABLE void updateDisplayImg(const QString &imgPath);
Q_INVOKABLE void saveStripe(const QString &path);
Q_INVOKABLE void setPatternType(const int patternType);
Q_INVOKABLE bool setNumberAttribute(const QString& attributeName,
const double val);
Q_INVOKABLE bool setBooleanAttribute(const QString& attributeName, const bool val);
Q_INVOKABLE double getNumberAttribute(const QString& attributeName);
Q_INVOKABLE bool getBooleanAttribute(const QString& attributeName);
Q_INVOKABLE QString getStringAttribute(const QString& attributeName);
Q_INVOKABLE const slmaster::cameras::FrameData& getCurFrame() { return frame_; }
std::shared_ptr<slmaster::cameras::SLCamera> getSLCamera() { return slCameraFactory_.getCamera(slmaster::cameras::CameraType(cameraType_)); }
std::vector<OrderTableRecord> getOrderTableRecord() { return orderTableRecord_; }
Q_INVOKABLE bool setNumberAttribute(const QString &attributeName,
const double val);
Q_INVOKABLE bool setBooleanAttribute(const QString &attributeName,
const bool val);
Q_INVOKABLE double getNumberAttribute(const QString &attributeName);
Q_INVOKABLE bool getBooleanAttribute(const QString &attributeName);
Q_INVOKABLE QString getStringAttribute(const QString &attributeName);
Q_INVOKABLE const slmaster::cameras::FrameData &getCurFrame() {
return frame_;
}
Q_INVOKABLE bool saveFrame(const QString &path);
std::shared_ptr<slmaster::cameras::SLCamera> getSLCamera() {
return slCameraFactory_.getCamera(
slmaster::cameras::CameraType(cameraType_));
}
std::vector<OrderTableRecord> getOrderTableRecord() {
return orderTableRecord_;
}
signals:
void stripeImgsChanged(const int num);
void frameCaptured();

private:
CameraEngine();
~CameraEngine();
CameraEngine(const CameraEngine&) = delete;
const CameraEngine& operator=(const CameraEngine&) = delete;
void defocusStripeCreate(std::vector<cv::Mat>& imgs, const int direction, const int cycles, const int shiftTime, AppType::DefocusEncoding method);
void realTimeRenderImg(const QImage& img);
CameraEngine(const CameraEngine &) = delete;
const CameraEngine &operator=(const CameraEngine &) = delete;
void defocusStripeCreate(std::vector<cv::Mat> &imgs, const int direction,
const int cycles, const int shiftTime,
AppType::DefocusEncoding method);
void realTimeRenderImg(const QImage &img);
void createTenLine();
void switchTrigMode(const bool isTrigLine, const int exposureTime);
std::vector<OrderTableRecord> orderTableRecord_;
std::vector<QImage> stripeImgs_;
AppType::ScanModeType scanMode_;
AppType::CameraType cameraType_;
AppType::PatternMethod patternType_;
static CameraEngine* engine_;
ImagePaintItem* stripePaintItem_ = nullptr;
ImagePaintItem* offlineCamPaintItem_ = nullptr;
ImagePaintItem* scanTexturePaintItem_ = nullptr;
static CameraEngine *engine_;
ImagePaintItem *stripePaintItem_ = nullptr;
ImagePaintItem *offlineCamPaintItem_ = nullptr;
ImagePaintItem *scanTexturePaintItem_ = nullptr;
std::thread onlineDetectThread_;
std::thread workThread_;
slmaster::cameras::SLCameraFactory slCameraFactory_;
std::shared_ptr<slmaster::cameras::Pattern> pattern_ = nullptr;
CameraModel* leftCamModel_ = nullptr;
CameraModel* rightCamModel_ = nullptr;
CameraModel* colorCamModel_ = nullptr;
CameraModel *leftCamModel_ = nullptr;
CameraModel *rightCamModel_ = nullptr;
CameraModel *colorCamModel_ = nullptr;
slmaster::cameras::FrameData frame_;
std::thread test_thread_;
std::atomic_bool appExit_;
Expand All @@ -116,4 +152,4 @@ class CameraEngine : public QObject {
std::atomic_bool isContinusStop_;
};

#endif// !__CAMERA_ENGINE_H_
#endif // !__CAMERA_ENGINE_H_
Loading

0 comments on commit edd2ea2

Please sign in to comment.