Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gamera_videos_no_ui
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
liusq
gamera_videos_no_ui
Commits
05584d53
Commit
05584d53
authored
Oct 12, 2024
by
郭峰
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature-1007488' into 'release'
增加人脸图片日志05 See merge request
!73
parents
116af852
0fd25424
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
78 additions
and
3 deletions
+78
-3
FaceReconitionHandle.cpp
+71
-3
FaceReconitionHandle.h
+5
-0
gamera_videos.pro
+2
-0
No files found.
FaceReconitionHandle.cpp
View file @
05584d53
...
...
@@ -5,9 +5,13 @@
#include <iostream>
#define cimg_display 0
#define cimg_use_jpeg
#define STB_IMAGE_IMPLEMENTATION
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "CImg.h"
#include "stb_image.h"
#include "stb_image_write.h"
using
namespace
cimg_library
;
...
...
@@ -41,8 +45,25 @@ cv::Mat FaceReconitionHandle::loadImage(const QString &path) {
qInfo
()
<<
"图像以OpenCV成功加载。"
;
return
image
;
}
return
loadImageFromByteStream
(
path
);
image
=
loadImageFromByteStream
(
path
);
if
(
!
image
.
empty
())
{
qInfo
()
<<
"图像以CImg成功加载。"
;
return
image
;
}
image
=
loadImageWithSTB
(
path
);
if
(
!
image
.
empty
())
{
qInfo
()
<<
"图像以stb_image成功加载。"
;
return
image
;
}
image
=
loadQImageFromByteStream
(
path
);
if
(
!
image
.
empty
())
{
qInfo
()
<<
"图像以QImage成功加载。"
;
return
image
;
}
qInfo
()
<<
"四种加载方式都不行"
;
return
cv
::
Mat
();
}
void
FaceReconitionHandle
::
initSourceImageMap
(
std
::
map
<
QString
,
QString
>&
maps
,
int
numberFaces
,
float
confidence
){
...
...
@@ -157,8 +178,55 @@ void FaceReconitionHandle::featureRemove(){
setImageChanged
(
false
);
}
}
cv
::
Mat
FaceReconitionHandle
::
loadImageWithSTB
(
const
QString
&
filename
)
{
int
width
,
height
,
channels
;
QByteArray
&&
b_filename
=
filename
.
toUtf8
();
char
*
c_filename
=
b_filename
.
data
();
// 使用 stb_image 加载图像,stbi_load 会根据图像格式返回数据
unsigned
char
*
data
=
stbi_load
(
c_filename
,
&
width
,
&
height
,
&
channels
,
0
);
if
(
!
data
)
{
qInfo
()
<<
"tb_image无法加载图像 "
<<
filename
;
return
cv
::
Mat
();
}
// 检查图像通道数,创建对应的 cv::Mat
cv
::
Mat
image
;
if
(
channels
==
1
)
{
// 灰度图像
image
=
cv
::
Mat
(
height
,
width
,
CV_8UC1
,
data
);
}
else
if
(
channels
==
3
)
{
// 彩色图像
image
=
cv
::
Mat
(
height
,
width
,
CV_8UC3
,
data
);
// OpenCV 默认使用 BGR,因此需要将 RGB 转换为 BGR
cv
::
cvtColor
(
image
,
image
,
cv
::
COLOR_RGB2BGR
);
}
else
if
(
channels
==
4
)
{
// 带 Alpha 通道的图像
image
=
cv
::
Mat
(
height
,
width
,
CV_8UC4
,
data
);
// RGB -> BGR(包括 Alpha 通道)
cv
::
cvtColor
(
image
,
image
,
cv
::
COLOR_RGBA2BGRA
);
}
// 释放 stb_image 加载的内存
stbi_image_free
(
data
);
return
image
;
}
cv
::
Mat
FaceReconitionHandle
::
loadQImageFromByteStream
(
const
QString
&
filePath
)
{
// 使用 QImage 加载图像
QImage
qimage
(
filePath
);
if
(
qimage
.
isNull
())
{
qInfo
()
<<
"QImage Error: 无法加载图像 "
<<
filePath
;
return
cv
::
Mat
();
}
// 将 QImage 转换为 cv::Mat
cv
::
Mat
mat
(
qimage
.
height
(),
qimage
.
width
(),
CV_8UC4
,
const_cast
<
uchar
*>
(
qimage
.
bits
()),
qimage
.
bytesPerLine
());
// 如果需要 BGR 格式
cv
::
cvtColor
(
mat
,
mat
,
cv
::
COLOR_RGBA2BGR
);
return
mat
;
}
cv
::
Mat
FaceReconitionHandle
::
loadImageFromByteStream
(
const
QString
&
filePath
)
{
try
{
...
...
FaceReconitionHandle.h
View file @
05584d53
...
...
@@ -28,6 +28,11 @@ public:
cv
::
Mat
loadImage
(
const
QString
&
path
);
cv
::
Mat
loadImageFromByteStream
(
const
QString
&
filePath
);
cv
::
Mat
loadQImageFromByteStream
(
const
QString
&
filePath
);
cv
::
Mat
loadImageWithSTB
(
const
QString
&
filename
);
bool
getImageChanged
()
const
;
void
setImageChanged
(
bool
imageChanged
);
...
...
gamera_videos.pro
View file @
05584d53
...
...
@@ -26,6 +26,8 @@ INCLUDEPATH+=/usr/local/include/XNetSDK
INCLUDEPATH
+=/
usr
/
local
/
include
/
human
INCLUDEPATH
+=/
usr
/
local
/
include
/
CImg
INCLUDEPATH
+=/
usr
/
local
/
include
/
mqtt
INCLUDEPATH
+=/
usr
/
local
/
include
/
stb_image
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment