Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
ftl
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nicolas Pope
ftl
Commits
34189c59
Commit
34189c59
authored
5 years ago
by
Sebastian Hahta
Browse files
Options
Downloads
Plain Diff
Merge branch 'feature/python-ftlf' into 'master'
python ftl-file v3 See merge request nicolas.pope/ftl!200
parents
c639ced2
9c5e9900
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!200
python ftl-file v3
Pipeline
#17353
passed
5 years ago
Stage: all
Stage: deploy
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
components/codecs/include/ftl/codecs/bitrates.hpp
+2
-2
2 additions, 2 deletions
components/codecs/include/ftl/codecs/bitrates.hpp
python/ftl/ftlstream.py
+49
-21
49 additions, 21 deletions
python/ftl/ftlstream.py
python/ftl/ftltypes.py
+3
-2
3 additions, 2 deletions
python/ftl/ftltypes.py
with
54 additions
and
25 deletions
components/codecs/include/ftl/codecs/bitrates.hpp
+
2
−
2
View file @
34189c59
...
...
@@ -13,8 +13,8 @@ namespace codecs {
enum
struct
codec_t
:
uint8_t
{
JPG
=
0
,
PNG
,
H264
,
HEVC
,
// H265
H264
,
HEVC
,
// H265
// TODO: Add audio codecs
WAV
,
...
...
This diff is collapsed.
Click to expand it.
python/ftl/ftlstream.py
+
49
−
21
View file @
34189c59
...
...
@@ -12,8 +12,6 @@ from . misc import is_iframe
from
.
import
ftltypes
as
ftl
from
.
import
libde265
_calib_fmt
=
"
@ddddIIdddd
"
try
:
import
cv2
as
cv
...
...
@@ -27,7 +25,7 @@ except ImportError:
'''
YCrCb to RGB, based on OpenCV documentation definition.
Note: It seems this implementation is not perfectly equivalent to
OpenCV
'
s
OpenCV
'
s
(results not exactly same, why?)
'''
rgb
=
np
.
zeros
(
img
.
shape
,
np
.
float
)
...
...
@@ -43,11 +41,25 @@ except ImportError:
return
rgb
.
round
().
astype
(
np
.
uint8
)
def
_ycbcr2rgb
(
img
):
rgb
=
np
.
zeros
(
img
.
shape
,
np
.
float
)
Y
=
img
[:,:,
0
].
astype
(
np
.
float
)
Cr
=
img
[:,:,
2
].
astype
(
np
.
float
)
Cb
=
img
[:,:,
1
].
astype
(
np
.
float
)
delta
=
128.0
rgb
[:,:,
0
]
=
Y
+
1.403
*
(
Cr
-
delta
)
rgb
[:,:,
1
]
=
Y
-
0.714
*
(
Cr
-
delta
)
-
0.344
*
(
Cb
-
delta
)
rgb
[:,:,
2
]
=
Y
+
1.773
*
(
Cb
-
delta
)
return
rgb
.
round
().
astype
(
np
.
uint8
)
class
FTLStreamWriter
:
def
__init__
(
self
,
file
):
def
__init__
(
self
,
file
,
version
=
2
):
self
.
_file
=
open
(
file
,
"
wb
"
)
self
.
_file
.
write
(
bytes
(
ord
(
c
)
for
c
in
"
FTLF
"
))
# magic
self
.
_file
.
write
(
bytes
([
2
]))
# version
self
.
_file
.
write
(
bytes
([
version
]))
# version
self
.
_file
.
write
(
bytes
([
0
]
*
64
))
# reserved
self
.
_packer
=
msgpack
.
Packer
(
strict_types
=
False
,
use_bin_type
=
True
)
...
...
@@ -94,7 +106,7 @@ class FTLStreamWriter:
if
codec
==
ftl
.
codec_t
.
PNG
:
if
ftl
.
is_float_channel
(
channel
):
# scaling always same (???)
data
=
data
.
astype
(
np
.
float
)
/
1000.0
data
=
(
data
*
1000
)
.
astype
(
np
.
uint16
)
params
=
[
cv
.
IMWRITE_PNG_COMPRESSION
,
9
]
retval
,
data
=
cv
.
imencode
(
"
.png
"
,
data
,
params
)
...
...
@@ -134,7 +146,8 @@ class FTLStreamWriter:
raise
NotImplementedError
(
"
todo
"
)
def
add_calibration
(
self
,
timestamp
,
source
,
data
):
struct
.
pack
(
_calib_fmt
,
*
data
)
# todo: Use msgpack format instead (ftlf v3+)
struct
.
pack
(
"
@ddddIIdddd
"
,
*
data
)
raise
NotImplementedError
(
"
todo
"
)
class
FTLStreamReader
:
...
...
@@ -180,8 +193,18 @@ class FTLStreamReader:
def
_update_calib
(
self
,
sp
,
p
):
'''
Update calibration.
'''
calibration
=
struct
.
unpack
(
_calib_fmt
,
p
.
data
[:(
4
*
8
+
2
*
4
+
4
*
8
)])
self
.
_calibration
[
sp
.
streamID
]
=
ftl
.
Camera
.
_make
(
calibration
)
if
p
.
codec
==
ftl
.
codec_t
.
MSGPACK
:
# TODO: channel and capabilities should be saved as well
calib
,
channel
,
capabilities
=
msgpack
.
unpackb
(
p
.
data
)
self
.
_calibration
[
sp
.
streamID
]
=
ftl
.
Camera
.
_make
(
calib
)
elif
p
.
codec
==
ftl
.
codec_t
.
CALIBRATION
:
calibration
=
struct
.
unpack
(
"
@ddddIIdddd
"
,
p
.
data
[:(
4
*
8
+
2
*
4
+
4
*
8
)])
self
.
_calibration
[
sp
.
streamID
]
=
ftl
.
Camera
.
_make
(
calibration
)
else
:
raise
Exception
(
"
Unknown codec %i for calibration
"
%
p
.
codec
)
def
_update_pose
(
self
,
sp
,
p
):
'''
Update pose
'''
...
...
@@ -226,7 +249,10 @@ class FTLStreamReader:
raise
NotImplementedError
(
"
non-color channel decoding not available
"
)
else
:
self
.
_frame
=
_ycrcb2rgb
(
img
)
if
self
.
_version
<
3
:
self
.
_frame
=
_ycrcb2rgb
(
img
)
else
:
self
.
_frame
=
_ycbcr2rgb
(
img
)
def
_decode_opencv
(
self
,
sp
,
p
):
try
:
...
...
@@ -254,30 +280,31 @@ class FTLStreamReader:
Reads data for until the next timestamp. Returns False if there is no
more data to read, otherwise returns True.
todo: make decoding optional
todo: make
(frame)
decoding optional
'''
self
.
_frame
=
None
try
:
self
.
_sp
,
self
.
_p
=
self
.
_read_next
()
self
.
_packets_read
+=
1
except
msgpack
.
OutOfData
:
return
False
if
self
.
_p
.
block_total
!=
1
or
self
.
_p
.
block_number
!=
0
:
raise
Exception
(
"
Unsupported block format (todo)
"
)
if
self
.
_p
.
codec
==
ftl
.
codec_t
.
JSON
:
self
.
_process_json
(
self
.
_sp
,
self
.
_p
)
el
if
self
.
_p
.
c
odec
==
ftl
.
codec_t
.
CALIBRATION
:
# calibration/pose cached
# todo: should be done by user instead?
if
self
.
_
s
p
.
c
hannel
==
ftl
.
Channel
.
Calibration
:
self
.
_update_calib
(
self
.
_sp
,
self
.
_p
)
elif
self
.
_p
.
c
odec
==
ftl
.
codec_t
.
POSE
:
elif
self
.
_
s
p
.
c
hannel
==
ftl
.
Channel
.
Pose
:
self
.
_update_pose
(
self
.
_sp
,
self
.
_p
)
elif
self
.
_p
.
codec
==
ftl
.
codec_t
.
HEVC
:
# decode if codec supported
if
self
.
_p
.
codec
==
ftl
.
codec_t
.
HEVC
:
self
.
_decode_hevc
(
self
.
_sp
,
self
.
_p
)
elif
self
.
_p
.
codec
==
ftl
.
codec_t
.
PNG
:
...
...
@@ -287,7 +314,8 @@ class FTLStreamReader:
self
.
_decode_opencv
(
self
.
_sp
,
self
.
_p
)
else
:
raise
Exception
(
"
unkowno codec %i
"
%
self
.
_p
.
codec
)
# todo (unsupported codec)
pass
return
True
...
...
@@ -336,7 +364,7 @@ class FTLStreamReader:
raise
ValueError
(
"
source id %i not found
"
%
source
)
def
get_Q
(
self
,
source
):
'''
Disparity to depth matrix
in
OpenCV
format
'''
'''
Disparity to depth matrix
(
OpenCV
)
'''
calib
=
self
.
get_calibration
(
source
)
Q
=
np
.
identity
(
4
,
dtype
=
np
.
float64
)
...
...
This diff is collapsed.
Click to expand it.
python/ftl/ftltypes.py
+
3
−
2
View file @
34189c59
...
...
@@ -65,7 +65,9 @@ class codec_t(IntEnum):
JSON
=
100
CALIBRATION
=
101
POSE
=
102
RAW
=
103
MSGPACK
=
103
,
STRING
=
104
,
RAW
=
105
definition_t
=
{
0
:
(
7680
,
4320
),
...
...
@@ -85,4 +87,3 @@ def get_definition(shape):
return
k
return
7
# (None)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment