Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Python_超人
宇宙模拟器
提交
3a39a517
宇宙模拟器
项目概览
Python_超人
/
宇宙模拟器
通知
19
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
宇宙模拟器
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
3a39a517
编写于
11月 10, 2023
作者:
三月三net
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Python超人-宇宙模拟器
上级
032adce8
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
71 addition
and
18 deletion
+71
-18
sim_scenes/solar_system/halley_comet_sim.py
sim_scenes/solar_system/halley_comet_sim.py
+1
-1
simulators/ursina/entities/video_recorder.py
simulators/ursina/entities/video_recorder.py
+70
-17
未找到文件。
sim_scenes/solar_system/halley_comet_sim.py
浏览文件 @
3a39a517
...
@@ -370,7 +370,7 @@ if __name__ == '__main__':
...
@@ -370,7 +370,7 @@ if __name__ == '__main__':
cosmic_bg
=
''
,
cosmic_bg
=
''
,
show_trail
=
True
,
show_trail
=
True
,
# bg_music='sounds/no_glory.mp3',
# bg_music='sounds/no_glory.mp3',
#
show_camera_info=False,
show_camera_info
=
False
,
save_as_video
=
True
,
save_as_video
=
True
,
show_control_info
=
False
,
show_control_info
=
False
,
timer_enabled
=
True
,
timer_enabled
=
True
,
...
...
simulators/ursina/entities/video_recorder.py
浏览文件 @
3a39a517
...
@@ -2,6 +2,7 @@ from ursina import *
...
@@ -2,6 +2,7 @@ from ursina import *
import
os
,
shutil
import
os
,
shutil
import
builtins
import
builtins
import
numpy
as
np
import
numpy
as
np
import
cv2
class
CubeMapVideoRecorder
(
Entity
):
class
CubeMapVideoRecorder
(
Entity
):
...
@@ -65,6 +66,13 @@ class VideoRecorder(Entity):
...
@@ -65,6 +66,13 @@ class VideoRecorder(Entity):
self
.
max_frames
=
int
(
self
.
duration
*
self
.
fps
)
self
.
max_frames
=
int
(
self
.
duration
*
self
.
fps
)
self
.
frames
=
[]
self
.
frames
=
[]
self
.
save_name
=
"video_temp.mp4"
self
.
video
=
self
.
create_video
(
864
,
1536
)
def
create_video
(
self
,
height
,
width
):
fourcc
=
cv2
.
VideoWriter_fourcc
(
*
'mp4v'
)
video
=
cv2
.
VideoWriter
(
self
.
save_name
,
fourcc
,
self
.
fps
,
(
width
,
height
))
return
video
def
start_recording
(
self
):
def
start_recording
(
self
):
print
(
'start recording,'
,
self
.
duration
,
self
.
file_path
)
print
(
'start recording,'
,
self
.
duration
,
self
.
file_path
)
...
@@ -74,40 +82,85 @@ class VideoRecorder(Entity):
...
@@ -74,40 +82,85 @@ class VideoRecorder(Entity):
self
.
max_frames
=
self
.
duration
*
self
.
fps
self
.
max_frames
=
self
.
duration
*
self
.
fps
if
not
self
.
file_path
.
exists
():
if
not
self
.
file_path
.
exists
():
self
.
file_path
.
mkdir
()
self
.
file_path
.
mkdir
()
base
.
movie
(
namePrefix
=
f
'
\\
video_temp
\\
{
self
.
video_name
}
'
,
duration
=
2.0
,
fps
=
30
,
format
=
'png'
,
sd
=
4
)
#
base.movie(namePrefix=f'\\video_temp\\{self.video_name}', duration=2.0, fps=30, format='png', sd=4)
self
.
recording
=
True
self
.
recording
=
True
invoke
(
self
.
stop_recording
,
delay
=
self
.
duration
)
#
invoke(self.stop_recording, delay=self.duration)
def
stop_recording
(
self
):
def
stop_recording
(
self
):
self
.
recording
=
False
self
.
recording
=
False
window
.
fps_counter
.
enabled
=
True
window
.
fps_counter
.
enabled
=
True
window
.
exit_button
.
visible
=
True
window
.
exit_button
.
visible
=
True
print
(
'stop recording'
)
print
(
'stop recording'
)
self
.
convert_to_gif
()
self
.
convert_to_mp4
()
def
convert_to_mp4
(
self
):
print
(
"视频保存中"
)
self
.
video
.
release
()
cv2
.
destroyAllWindows
()
# crop('video.mp4')
print
(
"视频保存完成"
)
print
(
self
.
save_name
)
def
screenshot_to_opencv_img
(
self
,
texture
):
# 将Texture对象转换为numpy数组
array
=
texture
.
to_array
()
# 将数组reshape为4D,以便opencv可以正确读取
array
=
np
.
reshape
(
array
,
(
texture
.
height
,
texture
.
width
,
-
1
))
# 转换为opencv读取的格式,注意需要先安装opencv库
img
=
cv2
.
cvtColor
(
array
,
cv2
.
COLOR_RGB2BGR
)
# 这里的cv2.COLOR_RGB2BGR是将RGB格式转换为BGR格式,因为Ursina使用的是RGB格式,而opencv使用的是BGR格式
return
img
def
update
(
self
):
def
update
(
self
):
if
not
self
.
recording
:
if
not
self
.
recording
:
return
return
self
.
t
+=
time
.
dt
self
.
t
+=
time
.
dt
if
self
.
t
>=
1
/
30
:
if
self
.
t
>=
1
/
30
:
base
.
screenshot
(
# base.screenshot(
namePrefix
=
'
\\
video_temp
\\
'
+
self
.
video_name
+
'_'
+
str
(
self
.
i
).
zfill
(
4
)
+
'.png'
,
# namePrefix='\\video_temp\\' + self.video_name + '_' + str(self.i).zfill(4) + '.png',
defaultFilename
=
0
,
# defaultFilename=0,
)
# )
self
.
t
=
0
self
.
t
=
0
# # self.frames.append(self.renderToPNM())
# image = deepcopy(camera.render_texture)
# image = base.win.getScreenshot()
# self.frames.append(self.renderToPNM())
# data = image.getRamImageAs("RGB").getData()
from
PIL
import
Image
# # from PIL import Image
import
io
# # image = Image.fromarray(data)
import
imageio
# # img = data.convert("RGBA")
image
=
base
.
win
.
getScreenshot
()
# data = np.array(data)
# image = image.get_internal_image()
data
=
image
.
getRamImageAs
(
"BGR"
).
getData
()
np_data
=
np
.
frombuffer
(
data
,
dtype
=
np
.
uint8
)
#
#
img_data
=
np
.
reshape
(
np_data
,
(
864
,
1536
,
3
))
# img = Image.fromarray(img_data)
# img = self.screenshot_to_opencv_img(image)
# img = np.array(data)
# image = Image.open(io.BytesIO(data))
# image = Image.fromarray(np.array(data))
# img = data.convert("RGBA")
# data = np.array(data)
# 获取图片的宽和高
width
=
img_data
.
shape
[
1
]
height
=
img_data
.
shape
[
0
]
# 创建一个空的数组,用于存储还原后的图像
normal_image
=
np
.
zeros
((
height
,
width
,
3
),
dtype
=
np
.
uint8
)
# 将颠倒图像的像素还原到正常图像中
for
i
in
range
(
height
):
for
j
in
range
(
width
):
normal_image
[
i
,
j
]
=
img_data
[
height
-
i
-
1
,
j
]
# # image = deepcopy(camera.render_texture)
# # image = deepcopy(camera.render_texture)
# self.frames.append(data)
# self.frames.append(data)
self
.
i
+=
1
self
.
i
+=
1
# img_bgr = cv2.cvtColor(img, cv2.COLOR_RGBA2BGR)
# if imageNum < self.fps * args.total_time:
# show_image(frame)
self
.
video
.
write
(
normal_image
)
# store screenshot in memory
# store screenshot in memory
# def renderToPNM(self):
# def renderToPNM(self):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录