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
01eb49b6
Commit
01eb49b6
authored
5 years ago
by
Nicolas Pope
Browse files
Options
Downloads
Patches
Plain Diff
Fixes for bad opencv depth encode
parent
77f572e1
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
SDK/Python/blender_script.py
+26
-9
26 additions, 9 deletions
SDK/Python/blender_script.py
components/codecs/src/generate.cpp
+1
-0
1 addition, 0 deletions
components/codecs/src/generate.cpp
components/codecs/src/opencv_encoder.cpp
+3
-3
3 additions, 3 deletions
components/codecs/src/opencv_encoder.cpp
with
30 additions
and
12 deletions
SDK/Python/blender_script.py
+
26
−
9
View file @
01eb49b6
...
@@ -140,19 +140,36 @@ def render():
...
@@ -140,19 +140,36 @@ def render():
rl
=
tree
.
nodes
.
new
(
'
CompositorNodeRLayers
'
)
rl
=
tree
.
nodes
.
new
(
'
CompositorNodeRLayers
'
)
v
=
tree
.
nodes
.
new
(
'
CompositorNodeViewer
'
)
v
=
tree
.
nodes
.
new
(
'
CompositorNodeViewer
'
)
v
.
use_alpha
=
True
v
.
use_alpha
=
False
#setup the depthmap calculation using blender's mist function:
#bpy.context.scene.render.layers['RenderLayer'].use_pass_mist = True
#bpy.context.scene.view_layers["View Layer"].use_pass_mist = True
#the depthmap can be calculated as the distance between objects and camera ('LINEAR'), or square/inverse square of the distance ('QUADRATIC'/'INVERSEQUADRATIC'):
bpy
.
context
.
scene
.
world
.
mist_settings
.
falloff
=
'
LINEAR
'
#minimum depth:
bpy
.
context
.
scene
.
world
.
mist_settings
.
intensity
=
0.1
#maximum depth (can be changed depending on the scene geometry to normalize the depth map whatever the camera orientation and position is):
bpy
.
context
.
scene
.
world
.
mist_settings
.
depth
=
8.0
links
.
new
(
rl
.
outputs
[
'
Depth
'
],
v
.
inputs
[
'
Image
'
])
bpy
.
ops
.
render
.
render
()
pixels
=
bpy
.
data
.
images
[
'
Viewer Node
'
]
depthim
=
(
np
.
array
(
pixels
.
pixels
[:]).
reshape
((
pixels
.
size
[
1
],
pixels
.
size
[
0
],
pixels
.
channels
))[:,:,
0
]).
astype
(
np
.
float32
)
# set invalid depth values to 0.0
depthim
[
depthim
>=
_d_max
]
=
0.0
print
(
np
.
amax
(
depthim
))
links
.
new
(
rl
.
outputs
[
'
Image
'
],
v
.
inputs
[
'
Image
'
])
links
.
new
(
rl
.
outputs
[
'
Image
'
],
v
.
inputs
[
'
Image
'
])
# depth cannot be accessed in python; hack uses alpha to store z-values
# depth cannot be accessed in python; hack uses alpha to store z-values
links
.
new
(
rl
.
outputs
[
'
Depth
'
],
v
.
inputs
[
'
Alpha
'
])
#
links.new(rl.outputs['Depth'], v.inputs['Alpha'])
bpy
.
ops
.
render
.
render
()
bpy
.
ops
.
render
.
render
()
pixels
=
bpy
.
data
.
images
[
'
Viewer Node
'
]
pixels
2
=
bpy
.
data
.
images
[
'
Viewer Node
'
]
im
=
np
.
array
(
pixels
.
pixels
[:]).
reshape
((
pixels
.
size
[
1
],
pixels
.
size
[
0
],
pixels
.
channels
))
im
=
np
.
array
(
pixels
2
.
pixels
[:]).
reshape
((
pixels
2
.
size
[
1
],
pixels
2
.
size
[
0
],
pixels
2
.
channels
))
# set invalid depth values to 0.0
return
(
im
[:,:,
0
:
3
]
*
255.0
).
astype
(
np
.
uint8
),
depthim
im
[:,:,
3
][
im
[:,:,
3
]
>=
_d_max
]
=
0.0
return
(
im
[:,:,
0
:
3
]
*
255.0
).
astype
(
np
.
uint8
),
(
im
[:,:,
3
]).
astype
(
np
.
float32
)
def
render_stereo
(
camera
,
baseline
=
0.15
):
def
render_stereo
(
camera
,
baseline
=
0.15
):
bpy
.
context
.
scene
.
camera
=
camera
bpy
.
context
.
scene
.
camera
=
camera
...
@@ -207,8 +224,8 @@ err = ftlImageWrite(stream, 0, 0, 3, 0, image.imL.ctypes.data_as(c_void_p))
...
@@ -207,8 +224,8 @@ err = ftlImageWrite(stream, 0, 0, 3, 0, image.imL.ctypes.data_as(c_void_p))
print
(
err
)
print
(
err
)
err
=
ftlImageWrite
(
stream
,
0
,
2
,
3
,
0
,
image
.
imR
.
ctypes
.
data_as
(
c_void_p
))
err
=
ftlImageWrite
(
stream
,
0
,
2
,
3
,
0
,
image
.
imR
.
ctypes
.
data_as
(
c_void_p
))
print
(
err
)
print
(
err
)
#
err = ftlImageWrite(stream, 0,
1
, 0, 0, image.depthL.ctypes.data_as(c_void_p))
err
=
ftlImageWrite
(
stream
,
0
,
22
,
0
,
0
,
image
.
depthL
.
ctypes
.
data_as
(
c_void_p
))
#
print(err)
print
(
err
)
err
=
ftlDestroyStream
(
stream
)
err
=
ftlDestroyStream
(
stream
)
print
(
err
)
print
(
err
)
This diff is collapsed.
Click to expand it.
components/codecs/src/generate.cpp
+
1
−
0
View file @
01eb49b6
...
@@ -30,6 +30,7 @@ void init_encoders() {
...
@@ -30,6 +30,7 @@ void init_encoders() {
encoders
.
push_back
(
new
ftl
::
codecs
::
OpenCVEncoder
(
definition_t
::
HD1080
,
definition_t
::
HD720
));
encoders
.
push_back
(
new
ftl
::
codecs
::
OpenCVEncoder
(
definition_t
::
HD1080
,
definition_t
::
HD720
));
encoders
.
push_back
(
new
ftl
::
codecs
::
OpenCVEncoder
(
definition_t
::
HD1080
,
definition_t
::
HD720
));
encoders
.
push_back
(
new
ftl
::
codecs
::
OpenCVEncoder
(
definition_t
::
HD1080
,
definition_t
::
HD720
));
encoders
.
push_back
(
new
ftl
::
codecs
::
OpenCVEncoder
(
definition_t
::
HD1080
,
definition_t
::
HD720
));
encoders
.
push_back
(
new
ftl
::
codecs
::
OpenCVEncoder
(
definition_t
::
SD576
,
definition_t
::
LD360
));
encoders
.
push_back
(
new
ftl
::
codecs
::
OpenCVEncoder
(
definition_t
::
SD576
,
definition_t
::
LD360
));
encoders
.
push_back
(
new
ftl
::
codecs
::
OpenCVEncoder
(
definition_t
::
SD576
,
definition_t
::
LD360
));
encoders
.
push_back
(
new
ftl
::
codecs
::
OpenCVEncoder
(
definition_t
::
SD576
,
definition_t
::
LD360
));
encoders
.
push_back
(
new
ftl
::
codecs
::
OpenCVEncoder
(
definition_t
::
SD576
,
definition_t
::
LD360
));
encoders
.
push_back
(
new
ftl
::
codecs
::
OpenCVEncoder
(
definition_t
::
SD576
,
definition_t
::
LD360
));
...
...
This diff is collapsed.
Click to expand it.
components/codecs/src/opencv_encoder.cpp
+
3
−
3
View file @
01eb49b6
...
@@ -56,9 +56,9 @@ bool OpenCVEncoder::encode(const cv::cuda::GpuMat &in, ftl::codecs::Packet &pkt)
...
@@ -56,9 +56,9 @@ bool OpenCVEncoder::encode(const cv::cuda::GpuMat &in, ftl::codecs::Packet &pkt)
in
.
download
(
tmp_
);
in
.
download
(
tmp_
);
//CHECK(cv::Size(ftl::codecs::getWidth(definition), ftl::codecs::getHeight(definition)) == in.size());
//CHECK(cv::Size(ftl::codecs::getWidth(definition), ftl::codecs::getHeight(definition)) == in.size());
if
(
!
is_colour
)
{
//
if (!is_colour) {
tmp_
.
convertTo
(
tmp_
,
CV_16U
,
1000.0
f
);
//
tmp_.convertTo(tmp_, CV_16U, 1000.0f);
}
//
}
int
width
=
ftl
::
codecs
::
getWidth
(
current_definition_
);
int
width
=
ftl
::
codecs
::
getWidth
(
current_definition_
);
int
height
=
ftl
::
codecs
::
getHeight
(
current_definition_
);
int
height
=
ftl
::
codecs
::
getHeight
(
current_definition_
);
...
...
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