Skip to content

Commit edd2ea2

Browse files
feat(CameraEngine.h/.cpp, cameras/): new features.
1. new coding stripe cropping function added. 2. the Save Point Cloud feature will save both texture and depth maps simultaneously.
1 parent 3144550 commit edd2ea2

11 files changed

+601
-421
lines changed

gui/qml/res/config/binocularCameraConfig.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@
5858
"type" : "number"
5959
},
6060
{
61-
"data" : 32.0,
61+
"data" : 64.0,
6262
"title" : "Cycles",
6363
"type" : "number"
6464
},
6565
{
66-
"data" : 18.0,
66+
"data" : 19.0,
6767
"title" : "Total Fringes",
6868
"type" : "number"
6969
},
@@ -106,7 +106,7 @@
106106
"type" : "bool"
107107
},
108108
{
109-
"data" : 1,
109+
"data" : 0,
110110
"title" : "Gpu Accelerate",
111111
"type" : "bool"
112112
},

gui/qml/res/config/monocularCameraConfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
"type" : "bool"
8282
},
8383
{
84-
"data" : 1,
84+
"data" : 0,
8585
"title" : "Gpu Accelerate",
8686
"type" : "bool"
8787
},

gui/qml/ui/global/Lang.qml

+6
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,8 @@ QtObject {
258258
property string height
259259
property string length
260260
property string inverse
261+
property string clip_width
262+
property string clip_height
261263

262264
function zh() {
263265
settings = "设置";
@@ -515,6 +517,8 @@ QtObject {
515517
height = "高度";
516518
length = "长度";
517519
inverse = "翻转特征方向";
520+
clip_width = "裁剪宽度";
521+
clip_height = "裁剪高度";
518522
}
519523

520524
function en() {
@@ -566,6 +570,8 @@ QtObject {
566570
error_diffusion_method = "Error Diffusion Method";
567571
img_width = "IMG Width";
568572
img_height = "IMG Height";
573+
clip_width = "Clip Width";
574+
clip_height = "Clip Height";
569575
cycles = "Cycles";
570576
shift_time = "Shift Time";
571577
stripe_img = "Stripe IMG";

gui/qml/ui/page/Page_Device.qml

+39-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ FluContentPage{
2828
property int defocus_encoding: pixel_depth ? AppType.Disable : AppType.OptimalPlusWithModulation
2929
property int img_width: Number(CameraEngine.getStringAttribute("DLP Width"))
3030
property int img_height: Number(CameraEngine.getStringAttribute("DLP Height"))
31+
property int clip_width: img_width
32+
property int clip_height: img_height
3133
property int cycles: CameraEngine.getNumberAttribute("Cycles")
3234
property int shiftTime: CameraEngine.getNumberAttribute("Phase Shift Times")
3335
property int connect_state : AppType.Disconnect
@@ -688,6 +690,42 @@ FluContentPage{
688690
}
689691
}
690692

693+
FluText {
694+
Layout.fillWidth: true
695+
text: Lang.clip_width
696+
font: FluTextStyle.BodyStrong
697+
}
698+
699+
FluText {
700+
Layout.fillWidth: true
701+
text: Lang.clip_height
702+
font: FluTextStyle.BodyStrong
703+
}
704+
705+
FluSpinBox {
706+
id: clip_width_spbox
707+
editable: true
708+
value: root.clip_width
709+
from: 0
710+
to: 9999999
711+
712+
onValueChanged: {
713+
root.clip_width = value;
714+
}
715+
}
716+
717+
FluSpinBox {
718+
id: clip_height_spbox
719+
editable: true
720+
value: root.clip_height
721+
from: 0
722+
to: 9999999
723+
724+
onValueChanged: {
725+
root.clip_height = value;
726+
}
727+
}
728+
691729
FluText {
692730
Layout.fillWidth: true
693731
text: Lang.cycles
@@ -763,7 +801,7 @@ FluContentPage{
763801
text: Lang.encode
764802

765803
onClicked: {
766-
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);
804+
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);
767805
stripe_index_indicator.pageCurrent = 1;
768806
CameraEngine.displayStripe(1);
769807
root.enableBurningStripe = true;

gui/qml/ui/page/Page_Scan.qml

+1
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,7 @@ FluContentPage {
545545

546546
onAccepted: {
547547
VTKProcessEngine.saveCloud(currentFile.toString());
548+
CameraEngine.saveFrame(currentFile.toString());
548549
}
549550
}
550551

gui/src/CameraEngine.cpp

+21-3
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ CameraEngine::~CameraEngine() {
6464
int CameraEngine::createStripe(const int pixelDepth, const int direction,
6565
const int stripeType, const int defocusMethod,
6666
const int imgWidth, const int imgHeight,
67+
const int clipWidth, const int clipHeight,
6768
const int cycles, const int shiftTime,
6869
const bool isKeepAdd) {
6970
qInfo() << "start create stripe...";
@@ -99,18 +100,24 @@ int CameraEngine::createStripe(const int pixelDepth, const int direction,
99100
AppType::DefocusEncoding(defocusMethod));
100101
}
101102

103+
if(clipWidth < imgWidth || clipHeight < imgHeight) {
104+
for (auto& img : imgs) {
105+
img(cv::Rect(0, 0, clipWidth, clipHeight)).copyTo(img);
106+
}
107+
}
108+
102109
auto formatType =
103110
AppType::PixelDepth(pixelDepth) == AppType::PixelDepth::OneBit
104111
? QImage::Format_Mono
105112
: QImage::Format_Grayscale8;
106113

107114
std::vector<QImage> tempStripes(imgs.size(),
108-
QImage(imgWidth, imgHeight, formatType));
115+
QImage(clipWidth, clipHeight, formatType));
109116
cv::parallel_for_(cv::Range(0, imgs.size()), [&](const cv::Range &range) {
110117
for (int i = range.start; i < range.end; ++i) {
111-
for (int j = 0; j < imgHeight; ++j) {
118+
for (int j = 0; j < clipHeight; ++j) {
112119
auto imgPtr = imgs[i].ptr(j);
113-
for (int k = 0; k < imgWidth; ++k) {
120+
for (int k = 0; k < clipWidth; ++k) {
114121
formatType == QImage::Format_Mono
115122
? tempStripes[i].setPixel(k, j, imgPtr[k])
116123
: tempStripes[i].setPixel(
@@ -966,3 +973,14 @@ void CameraEngine::tenLine() {
966973

967974
workThread_ = std::thread(&CameraEngine::createTenLine, this);
968975
}
976+
977+
bool CameraEngine::saveFrame(const QString& path) {
978+
auto fileName = path.mid(8, path.size() - 12);
979+
980+
qDebug() << QString("save frame, frame path is : %s").arg(fileName);
981+
982+
cv::imwrite(fileName.toStdString() + ".bmp", frame_.textureMap_);
983+
cv::imwrite(fileName.toStdString() + ".tiff", frame_.depthMap_);
984+
985+
return true;
986+
}

gui/src/CameraEngine.h

+77-41
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
11
/**
22
* @file CameraEngine.h
33
* @author Evans Liu (1369215984@qq.com)
4-
* @brief
4+
* @brief
55
* @version 0.1
66
* @date 2024-03-19
7-
*
7+
*
88
* @copyright Copyright (c) 2024
9-
*
9+
*
1010
*/
1111

1212
#ifndef __CAMERA_ENGINE_H_
1313
#define __CAMERA_ENGINE_H_
1414

15-
#include <vector>
1615
#include <thread>
16+
#include <vector>
17+
1718

1819
#include <QObject>
1920
#include <QThread>
2021

2122
#include <opencv2/opencv.hpp>
2223

2324
#include "AppType.h"
25+
#include "CameraModel.h"
2426
#include "ImagePaintItem.h"
2527
#include "typeDef.h"
26-
#include "CameraModel.h"
28+
2729

2830
#include <slmaster.h>
2931

@@ -33,28 +35,42 @@ class CameraEngine : public QObject {
3335
Q_PROPERTY_AUTO(bool, isConnected)
3436
Q_PROPERTY_AUTO(bool, isBurnWorkFinish)
3537
public:
36-
static CameraEngine* instance();
38+
static CameraEngine *instance();
3739
struct OrderTableRecord {
3840
OrderTableRecord() {}
39-
OrderTableRecord(const int patternsNum, const int shiftTime, const bool isVertical) : patternsNum_(patternsNum), shiftTime_(shiftTime), isVertical_(isVertical) {}
41+
OrderTableRecord(const int patternsNum, const int shiftTime,
42+
const bool isVertical)
43+
: patternsNum_(patternsNum), shiftTime_(shiftTime),
44+
isVertical_(isVertical) {}
4045
int patternsNum_;
4146
int shiftTime_;
4247
bool isVertical_;
4348
};
44-
//Device page
49+
// Device page
4550
Q_INVOKABLE void startDetectCameraState();
46-
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);
51+
Q_INVOKABLE int createStripe(const int pixelDepth, const int direction,
52+
const int stripeType, const int defocusMethod,
53+
const int imgWidth, const int imgHeight,
54+
const int clipWidth, const int clipHeight,
55+
const int cycles, const int shiftTime,
56+
const bool isKeepAdd);
4757
Q_INVOKABLE void displayStripe(const int stripeIndex);
4858
Q_INVOKABLE void selectCamera(const int cameraType);
4959
Q_INVOKABLE void setCameraJsonPath(const std::string jsonPath);
5060
Q_INVOKABLE bool connectCamera();
5161
Q_INVOKABLE bool disConnectCamera();
5262
Q_INVOKABLE void burnStripe();
53-
Q_INVOKABLE void bindStripePaintItem(ImagePaintItem* stripePaintItem) { stripePaintItem_ = stripePaintItem; }
54-
//offlineScan page
55-
Q_INVOKABLE void bindOfflineCamPaintItem(ImagePaintItem* camPaintItem) { offlineCamPaintItem_ = camPaintItem; }
56-
//scan page
57-
Q_INVOKABLE void setScanMode(const int scanMode) { scanMode_ = AppType::ScanModeType(scanMode); }
63+
Q_INVOKABLE void bindStripePaintItem(ImagePaintItem *stripePaintItem) {
64+
stripePaintItem_ = stripePaintItem;
65+
}
66+
// offlineScan page
67+
Q_INVOKABLE void bindOfflineCamPaintItem(ImagePaintItem *camPaintItem) {
68+
offlineCamPaintItem_ = camPaintItem;
69+
}
70+
// scan page
71+
Q_INVOKABLE void setScanMode(const int scanMode) {
72+
scanMode_ = AppType::ScanModeType(scanMode);
73+
}
5874
Q_INVOKABLE void projectOnce();
5975
Q_INVOKABLE void projectContinues();
6076
Q_INVOKABLE void pauseProject(const bool isResume);
@@ -64,50 +80,70 @@ class CameraEngine : public QObject {
6480
Q_INVOKABLE void startScan();
6581
Q_INVOKABLE void continuesScan();
6682
Q_INVOKABLE void pauseScan();
67-
Q_INVOKABLE void bindOfflineLeftCamModel(CameraModel* model) { leftCamModel_ = model; }
68-
Q_INVOKABLE void bindOfflineRightCamModel(CameraModel* model) { rightCamModel_ = model; }
69-
Q_INVOKABLE void bindOfflineColorCamModel(CameraModel* model) { colorCamModel_ = model; }
70-
Q_INVOKABLE void bindScanTexturePaintItem(ImagePaintItem* paintItem) { scanTexturePaintItem_ = paintItem; }
71-
Q_INVOKABLE void updateDisplayImg(const QString& imgPath);
72-
Q_INVOKABLE void saveStripe(const QString& path);
83+
Q_INVOKABLE void bindOfflineLeftCamModel(CameraModel *model) {
84+
leftCamModel_ = model;
85+
}
86+
Q_INVOKABLE void bindOfflineRightCamModel(CameraModel *model) {
87+
rightCamModel_ = model;
88+
}
89+
Q_INVOKABLE void bindOfflineColorCamModel(CameraModel *model) {
90+
colorCamModel_ = model;
91+
}
92+
Q_INVOKABLE void bindScanTexturePaintItem(ImagePaintItem *paintItem) {
93+
scanTexturePaintItem_ = paintItem;
94+
}
95+
Q_INVOKABLE void updateDisplayImg(const QString &imgPath);
96+
Q_INVOKABLE void saveStripe(const QString &path);
7397
Q_INVOKABLE void setPatternType(const int patternType);
74-
Q_INVOKABLE bool setNumberAttribute(const QString& attributeName,
75-
const double val);
76-
Q_INVOKABLE bool setBooleanAttribute(const QString& attributeName, const bool val);
77-
Q_INVOKABLE double getNumberAttribute(const QString& attributeName);
78-
Q_INVOKABLE bool getBooleanAttribute(const QString& attributeName);
79-
Q_INVOKABLE QString getStringAttribute(const QString& attributeName);
80-
Q_INVOKABLE const slmaster::cameras::FrameData& getCurFrame() { return frame_; }
81-
std::shared_ptr<slmaster::cameras::SLCamera> getSLCamera() { return slCameraFactory_.getCamera(slmaster::cameras::CameraType(cameraType_)); }
82-
std::vector<OrderTableRecord> getOrderTableRecord() { return orderTableRecord_; }
98+
Q_INVOKABLE bool setNumberAttribute(const QString &attributeName,
99+
const double val);
100+
Q_INVOKABLE bool setBooleanAttribute(const QString &attributeName,
101+
const bool val);
102+
Q_INVOKABLE double getNumberAttribute(const QString &attributeName);
103+
Q_INVOKABLE bool getBooleanAttribute(const QString &attributeName);
104+
Q_INVOKABLE QString getStringAttribute(const QString &attributeName);
105+
Q_INVOKABLE const slmaster::cameras::FrameData &getCurFrame() {
106+
return frame_;
107+
}
108+
Q_INVOKABLE bool saveFrame(const QString &path);
109+
std::shared_ptr<slmaster::cameras::SLCamera> getSLCamera() {
110+
return slCameraFactory_.getCamera(
111+
slmaster::cameras::CameraType(cameraType_));
112+
}
113+
std::vector<OrderTableRecord> getOrderTableRecord() {
114+
return orderTableRecord_;
115+
}
83116
signals:
84117
void stripeImgsChanged(const int num);
85118
void frameCaptured();
119+
86120
private:
87121
CameraEngine();
88122
~CameraEngine();
89-
CameraEngine(const CameraEngine&) = delete;
90-
const CameraEngine& operator=(const CameraEngine&) = delete;
91-
void defocusStripeCreate(std::vector<cv::Mat>& imgs, const int direction, const int cycles, const int shiftTime, AppType::DefocusEncoding method);
92-
void realTimeRenderImg(const QImage& img);
123+
CameraEngine(const CameraEngine &) = delete;
124+
const CameraEngine &operator=(const CameraEngine &) = delete;
125+
void defocusStripeCreate(std::vector<cv::Mat> &imgs, const int direction,
126+
const int cycles, const int shiftTime,
127+
AppType::DefocusEncoding method);
128+
void realTimeRenderImg(const QImage &img);
93129
void createTenLine();
94130
void switchTrigMode(const bool isTrigLine, const int exposureTime);
95131
std::vector<OrderTableRecord> orderTableRecord_;
96132
std::vector<QImage> stripeImgs_;
97133
AppType::ScanModeType scanMode_;
98134
AppType::CameraType cameraType_;
99135
AppType::PatternMethod patternType_;
100-
static CameraEngine* engine_;
101-
ImagePaintItem* stripePaintItem_ = nullptr;
102-
ImagePaintItem* offlineCamPaintItem_ = nullptr;
103-
ImagePaintItem* scanTexturePaintItem_ = nullptr;
136+
static CameraEngine *engine_;
137+
ImagePaintItem *stripePaintItem_ = nullptr;
138+
ImagePaintItem *offlineCamPaintItem_ = nullptr;
139+
ImagePaintItem *scanTexturePaintItem_ = nullptr;
104140
std::thread onlineDetectThread_;
105141
std::thread workThread_;
106142
slmaster::cameras::SLCameraFactory slCameraFactory_;
107143
std::shared_ptr<slmaster::cameras::Pattern> pattern_ = nullptr;
108-
CameraModel* leftCamModel_ = nullptr;
109-
CameraModel* rightCamModel_ = nullptr;
110-
CameraModel* colorCamModel_ = nullptr;
144+
CameraModel *leftCamModel_ = nullptr;
145+
CameraModel *rightCamModel_ = nullptr;
146+
CameraModel *colorCamModel_ = nullptr;
111147
slmaster::cameras::FrameData frame_;
112148
std::thread test_thread_;
113149
std::atomic_bool appExit_;
@@ -116,4 +152,4 @@ class CameraEngine : public QObject {
116152
std::atomic_bool isContinusStop_;
117153
};
118154

119-
#endif// !__CAMERA_ENGINE_H_
155+
#endif // !__CAMERA_ENGINE_H_

0 commit comments

Comments
 (0)