nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix

python3Packages.bpycv: init at 0.2.43

Signed-off-by: lucasew <lucas59356@gmail.com>

lucasew 2913e239 568e0bc4

+140
+76
pkgs/development/python-modules/bpycv/bpycv-test.py
··· 1 + # based on https://github.com/DIYer22/bpycv/blob/c576e01622d87eb3534f73bf1a5686bd2463de97/example/ycb_demo.py 2 + import bpy 3 + import bpycv 4 + 5 + import os 6 + import glob 7 + import random 8 + 9 + example_data_dir = os.environ['BPY_EXAMPLE_DATA'] 10 + 11 + models = sorted(glob.glob(os.path.join(example_data_dir, "model", "*", "*.obj"))) 12 + cat_id_to_model_path = dict(enumerate(sorted(models), 1)) 13 + 14 + distractors = sorted(glob.glob(os.path.join(example_data_dir, "distractor", "*.obj"))) 15 + 16 + bpycv.clear_all() 17 + bpy.context.scene.frame_set(1) 18 + bpy.context.scene.render.engine = "CYCLES" 19 + bpy.context.scene.cycles.samples = 32 20 + bpy.context.scene.render.resolution_y = 1024 21 + bpy.context.scene.render.resolution_x = 1024 22 + 23 + # A transparency stage for holding rigid body 24 + stage = bpycv.add_stage(transparency=True) 25 + 26 + bpycv.set_cam_pose(cam_radius=1, cam_deg=45) 27 + 28 + hdri_dir = os.path.join(example_data_dir, "background_and_light") 29 + hdri_manager = bpycv.HdriManager( 30 + hdri_dir=hdri_dir, download=False 31 + ) # if download is True, will auto download .hdr file from HDRI Haven 32 + hdri_path = hdri_manager.sample() 33 + bpycv.load_hdri_world(hdri_path, random_rotate_z=True) 34 + 35 + # load 5 objects 36 + for index in range(5): 37 + cat_id = random.choice(list(cat_id_to_model_path)) 38 + model_path = cat_id_to_model_path[cat_id] 39 + obj = bpycv.load_obj(model_path) 40 + obj.location = ( 41 + random.uniform(-0.2, 0.2), 42 + random.uniform(-0.2, 0.2), 43 + random.uniform(0.1, 0.3), 44 + ) 45 + obj.rotation_euler = [random.uniform(-3.1415, 3.1415) for _ in range(3)] 46 + # set each instance a unique inst_id, which is used to generate instance annotation. 47 + obj["inst_id"] = cat_id * 1000 + index 48 + with bpycv.activate_obj(obj): 49 + bpy.ops.rigidbody.object_add() 50 + 51 + # load 6 distractors 52 + for index in range(6): 53 + distractor_path = random.choice(distractors) 54 + target_size = random.uniform(0.1, 0.3) 55 + distractor = bpycv.load_distractor(distractor_path, target_size=target_size) 56 + distractor.location = ( 57 + random.uniform(-0.2, 0.2), 58 + random.uniform(-0.2, 0.2), 59 + random.uniform(0.1, 0.3), 60 + ) 61 + distractor.rotation_euler = [random.uniform(-3.1415, 3.1415) for _ in range(3)] 62 + with bpycv.activate_obj(distractor): 63 + bpy.ops.rigidbody.object_add() 64 + 65 + # run pyhsic engine for 20 frames 66 + for i in range(20): 67 + bpy.context.scene.frame_set(bpy.context.scene.frame_current + 1) 68 + 69 + # render image, instance annoatation and depth in one line code 70 + result = bpycv.render_data() 71 + 72 + dataset_dir = "./dataset" 73 + result.save(dataset_dir=dataset_dir, fname="0", save_blend=True) 74 + print(f'Save to "{dataset_dir}"') 75 + print(f'Open "{dataset_dir}/vis/" to see visualize result.') 76 +
+62
pkgs/development/python-modules/bpycv/default.nix
··· 1 + { lib 2 + , buildPythonPackage 3 + , fetchPypi 4 + , fetchFromGitHub 5 + , fetchurl 6 + , writeText 7 + , blender 8 + , minexr 9 + , beautifulsoup4 10 + , zcs 11 + , requests 12 + , opencv3 13 + , boxx 14 + }: 15 + 16 + buildPythonPackage rec { 17 + pname = "bpycv"; 18 + version = "0.2.43"; 19 + 20 + src = fetchPypi { 21 + inherit pname version; 22 + sha256 = "sha256-6LXhKuNkX3yKeZARLXmOVNAUQhJghtzKhnszJ1G/a8U="; 23 + }; 24 + 25 + propagatedBuildInputs = [ 26 + beautifulsoup4 27 + minexr 28 + zcs 29 + requests 30 + opencv3 31 + boxx 32 + ]; 33 + 34 + postPatch = '' 35 + sed -i 's/opencv-python//g' requirements.txt 36 + ''; 37 + 38 + # pythonImportsCheck = [ "bpycv" ]; # this import depends on bpy that is only available inside blender 39 + checkInputs = [ blender ]; 40 + checkPhase = let 41 + bpycv_example_data = fetchFromGitHub { 42 + owner = "DIYer22"; 43 + repo = "bpycv_example_data"; 44 + sha256 = "sha256-dGb6KvbXTGTu5f4AqhA+i4AwTqBoR5SdXk0vsMEcD3Q="; 45 + rev = "6ce0e65c107d572011394da16ffdf851e988dbb4"; 46 + }; 47 + in '' 48 + TEMPDIR=$(mktemp -d) 49 + pushd $TEMPDIR 50 + cp -r ${bpycv_example_data} example_data 51 + chmod +w -R example_data 52 + BPY_EXAMPLE_DATA=${bpycv_example_data} blender -b -P ${./bpycv-test.py} 53 + popd 54 + ''; 55 + 56 + meta = with lib; { 57 + description = "Computer vision utils for Blender"; 58 + homepage = "https://github.com/DIYer22/bpycv"; 59 + license = licenses.mit; 60 + maintainers = with maintainers; [ lucasew ]; 61 + }; 62 + }
+2
pkgs/top-level/python-packages.nix
··· 1302 1302 1303 1303 bottleneck = callPackage ../development/python-modules/bottleneck { }; 1304 1304 1305 + bpycv = callPackage ../development/python-modules/bpycv {}; 1306 + 1305 1307 bpython = callPackage ../development/python-modules/bpython { }; 1306 1308 1307 1309 braceexpand = callPackage ../development/python-modules/braceexpand { };