python3Packages.bpycv: refactor + passthru.tests

Signed-off-by: lucasew <lucas59356@gmail.com>
This commit is contained in:
lucasew 2023-05-10 17:42:32 -03:00
parent fd34bc39e4
commit 3acc4aff87
2 changed files with 46 additions and 32 deletions

View file

@ -5,8 +5,11 @@ import bpycv
import os
import glob
import random
from pathlib import Path
example_data_dir = os.environ['BPY_EXAMPLE_DATA']
out_dir = Path(os.environ['out'])
out_dir.mkdir(parents=True, exist_ok=True)
models = sorted(glob.glob(os.path.join(example_data_dir, "model", "*", "*.obj")))
cat_id_to_model_path = dict(enumerate(sorted(models), 1))
@ -19,6 +22,7 @@ bpy.context.scene.render.engine = "CYCLES"
bpy.context.scene.cycles.samples = 32
bpy.context.scene.render.resolution_y = 1024
bpy.context.scene.render.resolution_x = 1024
bpy.context.view_layer.cycles.denoising_store_passes = False
# A transparency stage for holding rigid body
stage = bpycv.add_stage(transparency=True)
@ -69,8 +73,8 @@ for i in range(20):
# render image, instance annoatation and depth in one line code
result = bpycv.render_data()
dataset_dir = "./dataset"
result.save(dataset_dir=dataset_dir, fname="0", save_blend=True)
print(f'Save to "{dataset_dir}"')
print(f'Open "{dataset_dir}/vis/" to see visualize result.')
result.save(dataset_dir=str(out_dir.resolve()), fname="0", save_blend=True)
print(f'Save to "{out_dir}"')
print(f'Open "{out_dir}/vis/" to see visualize result.')

View file

@ -1,16 +1,21 @@
{ lib
, buildPythonPackage
, fetchPypi
, fetchFromGitHub
, fetchurl
, writeText
, blender
, minexr
{ stdenv
, lib
, beautifulsoup4
, zcs
, requests
, opencv3
, blender
, blender-with-packages
, boxx
, bpycv
, buildPythonPackage
, fetchFromGitHub
, fetchPypi
, fetchurl
, minexr
, opencv3
, python3Packages
, requests
, runCommand
, writeText
, zcs
}:
buildPythonPackage rec {
@ -37,27 +42,32 @@ buildPythonPackage rec {
'';
# pythonImportsCheck = [ "bpycv" ]; # this import depends on bpy that is only available inside blender
nativeCheckInputs = [ blender ];
checkPhase = let
bpycv_example_data = fetchFromGitHub {
owner = "DIYer22";
repo = "bpycv_example_data";
hash = "sha256-dGb6KvbXTGTu5f4AqhA+i4AwTqBoR5SdXk0vsMEcD3Q=";
rev = "6ce0e65c107d572011394da16ffdf851e988dbb4";
};
in ''
TEMPDIR=$(mktemp -d)
pushd $TEMPDIR
cp -r ${bpycv_example_data} example_data
chmod +w -R example_data
BPY_EXAMPLE_DATA=${bpycv_example_data} blender -b -P ${./bpycv-test.py}
popd
'';
doCheck = false;
passthru.tests = {
render = runCommand "bpycv-render-test" {
BPY_EXAMPLE_DATA = fetchFromGitHub {
owner = "DIYer22";
repo = "bpycv_example_data";
hash = "sha256-dGb6KvbXTGTu5f4AqhA+i4AwTqBoR5SdXk0vsMEcD3Q=";
rev = "6ce0e65c107d572011394da16ffdf851e988dbb4";
};
nativeBuildInputs = [
((blender-with-packages.override {inherit blender python3Packages;}) {
packages = [ bpycv ];
})
];
} ''
blender-wrapped -b -P ${./bpycv-test.py}
'';
};
meta = with lib; {
description = "Computer vision utils for Blender";
homepage = "https://github.com/DIYer22/bpycv";
license = licenses.mit;
maintainers = with maintainers; [ lucasew ];
maintainers = [ maintainers.lucasew ];
broken = stdenv.isAarch64;
inherit (blender.meta) platforms;
};
}