Skip to content

Commit ecdcb5f

Browse files
committed
makeSquare
1 parent 1e7c9ab commit ecdcb5f

File tree

4 files changed

+27
-8
lines changed

4 files changed

+27
-8
lines changed

app/qml/screens/CameraSettings.qml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ Item {
7474
var path = selectedFile.toString();
7575
path = path.replace(/^(file:\/{3})|(qrc:\/{2})|(http:\/{2})/,"");
7676
vr.source = path
77+
vr.waitKeyTimeout = 65
7778
}
7879
}
7980
}
@@ -89,11 +90,11 @@ Item {
8990
TextField {
9091
id: timeoutTextId
9192
width: 100
93+
text: vr.waitKeyTimeout
9294
implicitHeight: rowHeight - 10
9395
placeholderText: qsTr("timeout")
94-
text: vr.waitKeyTimeout
95-
horizontalAlignment: TextInput.AlignHCenter
9696
verticalAlignment: TextInput.AlignVCenter
97+
horizontalAlignment: TextInput.AlignHCenter
9798
onEditingFinished: {
9899
vr.waitKeyTimeout = parseInt(timeoutTextId.text)
99100
}

cvl/cvl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,12 @@ struct camera {
8787
}
8888
cv::Mat f_in;
8989
while (!_stop) {
90-
_count++;
9190
cap >> f_in;
91+
if (f_in.empty() || f_in.cols <= 0 || f_in.rows <= 0) continue;
92+
_count++;
93+
auto f_square = cvl::geometry::makeSquare(f_in);
9294
if ((_count % cc->_skipFrames) == 0) {
93-
q_in.enqueue(f_in);
95+
q_in.enqueue(f_square);
9496
auto f_out = q_out.dequeue();
9597
if (!f_out.empty()) {
9698
if (_frame_cbk) {

cvl/detector.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ struct BackgroundSubtractor : public Detector {
241241
cv::Mat fgMask;
242242
cv::Mat gray, blurred;
243243
cv::cvtColor(frame, gray, cv::COLOR_BGR2GRAY);
244-
cv::GaussianBlur(gray, blurred, cv::Size(5, 5), 0);
244+
cv::GaussianBlur(gray, blurred, cv::Size(12, 12), 0);
245245
pBackgroundSubtractor[cc->_mocapAlgo]->apply(blurred, fgMask, 0.05);
246246
cv::Mat kernel = cv::getStructuringElement(cv::MORPH_RECT, cv::Size(3, 3));
247247
cv::morphologyEx(fgMask, fgMask, cv::MORPH_OPEN, kernel);
@@ -275,10 +275,10 @@ struct FaceRecognizer {
275275
std::cerr << e.what() << std::endl;
276276
}
277277
_model = cv::face::LBPHFaceRecognizer::create();
278-
_model->setRadius(1);
279-
_model->setNeighbors(8);
280278
_model->setGridX(4);
281279
_model->setGridY(4);
280+
_model->setRadius(1);
281+
_model->setNeighbors(8);
282282
if (_images.size() && _ids.size()) {
283283
_model->train(_images, _ids);
284284
}
@@ -298,10 +298,10 @@ struct FaceRecognizer {
298298

299299
auto predict(const cv::Mat& mat, spcc cc) {
300300
int id = -1;
301-
double confidence = 0.0;
302301
cv::Mat gray;
303302
cv::cvtColor(mat, gray, cv::COLOR_BGR2GRAY);
304303
cv::resize(gray, gray, cv::Size(100, 100));
304+
double confidence = 0.0;
305305
_model->predict(gray, id, confidence);
306306
std::pair<int, double> pair = {-1, 0.0};
307307
if (confidence <= cc->_facerecConfidence) {

cvl/geometry.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,22 @@ inline auto computeLaplacianVariance(const cv::Mat& img) {
137137
return variance;
138138
}
139139

140+
inline auto makeSquare(const cv::Mat& input, const cv::Scalar& paddingColor = cv::Scalar(0, 0, 0)) {
141+
int width = input.cols;
142+
int height = input.rows;
143+
int maxDim = std::max(width, height);
144+
// Create a square black image
145+
cv::Mat square = cv::Mat::zeros(cv::Size(maxDim, maxDim), input.type());
146+
square.setTo(paddingColor);
147+
// Compute top-left corner where the image will be placed
148+
int xOffset = (maxDim - width) / 2;
149+
int yOffset = (maxDim - height) / 2;
150+
// Define ROI and copy input frame into the center
151+
cv::Rect roi(xOffset, yOffset, width, height);
152+
input.copyTo(square(roi));
153+
return square;
154+
}
155+
140156
}
141157
}
142158
#endif

0 commit comments

Comments
 (0)