홍든램지의 보일러실

BlenderProc 설치와 python 예시 본문

오픈소스 프로젝트

BlenderProc 설치와 python 예시

예비보일 2023. 3. 14. 17:31
반응형

BlenderProc를 통해 대규모 데이터셋을 구성하기 위해서는 블랜더를 설치해야한다.

 

1. 블렌더 다운로드

https://www.blender.org/download/

 

Download — blender.org

The Freedom to Create.

www.blender.org

BlenderProc는 블렌더 3D모델링 소프트웨어 위에 구축된다. 다라서 먼저 블렌더를 다운로드하고 설치해야 한다. 블랜더 공식 웹사이트에서 최신 버전의 블랜더를 사운로드 할수 있다.

 

2.BlenderProc 설치:

방법에는 두가지가 있다.

2-1. pip 를 이용해서 설치하는 방법

pip install blenderproc

위 커맨드를 통해서 pip package로 설치가 가능하다.

 

2-2. Git clone 을 통한 방법

블렌더를 설치하면 공식 Github 리포지토리에서 최신 버전의 BlenderProc을 다운받을수 있다. 운영체제의 경우 Window, Linux or macOS에 적합하다.

https://github.com/DLR-RM/BlenderProc

 

GitHub - DLR-RM/BlenderProc: A procedural Blender pipeline for photorealistic training image generation

A procedural Blender pipeline for photorealistic training image generation - GitHub - DLR-RM/BlenderProc: A procedural Blender pipeline for photorealistic training image generation

github.com

필자는 Ubuntu에서 사용하고 있으며 아래 명령어를 통해 설치한다.

git clone https://github.com/DLR-RM/BlenderProc.git

주의: blenderproc 명령을 사용하여 시스템 모든 위치에서 blenderproc를 사용하려면 local pip에 설치되어야한다.

 

cd BlenderProc
pip install -e .

BlenderProc 디렉토리로 이동하여 설치를 진행한다.

 

 

간단한 예시로 

import blenderproc as bproc
import numpy as np

bproc.init()

# Create a simple object:
obj = bproc.object.create_primitive("MONKEY")

# Create a point light next to it
light = bproc.types.Light()
light.set_location([2, -2, 0])
light.set_energy(300)

# Set the camera to be in front of the object
cam_pose = bproc.math.build_transformation_mat([0, -5, 0], [np.pi / 2, 0, 0])
bproc.camera.add_camera_pose(cam_pose)

# Render the scene
data = bproc.renderer.render()

# Write the rendering into an hdf5 file
bproc.writer.write_hdf5("[저장할경로]", data)

폴더를 하나 생성하고 아래 커맨드로 위 파이썬 파일을 실행한다.

 

cd [생성한 경로]
blenderproc run [파일이름].py

# 예시
cd project_py
blenderproc run test.py

 

해당결로에 생성된 파일을 시각화 해보자

blenderproc vis hdf5 0.hdf5

위와 같은 결과를 얻을 수 있다.

 

 

블랜더 GUI Debugging 모드도 사용 할 수 있다.

실질적으로 블랜더에서 어떻게 작동하는지 보기 위해서 debug 명령어를 사용해서 확인할 수 있다.

blenderproc debug test.py

위 명령어를 입력하게 되면 아래와 같은 화면으로 전환 되며 run blenderproc 를 클릭하면 실행할 수 있다.

이상으로 설치와 예제를 실행해보았다.

반응형
Comments