Merge pull request #153896 from lucasew/packages/bpycv

This commit is contained in:
Sandro 2022-01-13 18:22:53 +01:00 committed by GitHub
commit 5e1226aef7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 410 additions and 0 deletions

View file

@ -0,0 +1,39 @@
{ stdenv
, lib
, blender
, makeWrapper
, python39Packages
}:
{ name ? "wrapped"
, packages ? []
}:
stdenv.mkDerivation {
pname = "blender-${name}";
inherit (blender) version;
src = blender;
nativeBuildInputs = [ python39Packages.wrapPython makeWrapper ];
installPhase = ''
mkdir $out/{share/applications,bin} -p
sed 's/Exec=blender/Exec=blender-${name}/g' $src/share/applications/blender.desktop > $out/share/applications/blender-${name}.desktop
cp -r $src/share/blender $out/share
cp -r $src/share/doc $out/share
cp -r $src/share/icons $out/share
buildPythonPath "$pythonPath"
echo '#!/usr/bin/env bash ' >> $out/bin/blender-${name}
for p in $program_PATH; do
echo "export PATH=\$PATH:$p " >> $out/bin/blender-${name}
done
for p in $program_PYTHONPATH; do
echo "export PYTHONPATH=\$PYTHONPATH:$p " >> $out/bin/blender-${name}
done
echo 'exec ${blender}/bin/blender "$@"' >> $out/bin/blender-${name}
chmod +x $out/bin/blender-${name}
'';
pythonPath = packages;
meta = blender.meta;
}

View file

@ -0,0 +1,30 @@
{ lib
, buildPythonPackage
, fetchPypi
, pythonOlder
, pyquaternion
, numpy
}:
buildPythonPackage rec {
pname = "bbox";
version = "0.9.2";
disabled = pythonOlder "3.6";
src = fetchPypi {
inherit pname version;
sha256 = "sha256-ucR7mg9eubEefjC7ratEgrb9h++a26z8KV38n3N2kcw=";
};
propagatedBuildInputs = [ pyquaternion numpy ];
pythonImportsCheck = [ "bbox" ];
meta = with lib; {
description = "Python library for 2D/3D bounding boxes";
homepage = "https://github.com/varunagrawal/bbox";
license = licenses.mit;
maintainers = with maintainers; [ lucasew ];
};
}

View file

@ -0,0 +1,57 @@
{ lib
, buildPythonPackage
, fetchPypi
, python
, xvfb-run
, matplotlib
, scikitimage
, numpy
, pandas
, imageio
, snakeviz
, fn
, pyopengl
, seaborn
, pytorch
, torchvision
}:
buildPythonPackage rec {
pname = "boxx";
version = "0.9.9";
src = fetchPypi {
inherit pname version;
sha256 = "sha256-Mc6R6ruUVhFs2D0CTJsAiM9aGOusS973hRS5r2kQsy4=";
};
propagatedBuildInputs = [
matplotlib
scikitimage
numpy
pandas
imageio
snakeviz
fn
pyopengl
seaborn
];
pythonImportsCheck = [ "boxx" ];
checkInputs = [
xvfb-run
pytorch
torchvision
];
checkPhase = ''
xvfb-run ${python.interpreter} -m unittest
'';
meta = with lib; {
description = "Tool-box for efficient build and debug in Python. Especially for Scientific Computing and Computer Vision.";
homepage = "https://github.com/DIYer22/boxx";
license = licenses.mit;
maintainers = with maintainers; [ lucasew ];
};
}

View file

@ -0,0 +1,76 @@
# based on https://github.com/DIYer22/bpycv/blob/c576e01622d87eb3534f73bf1a5686bd2463de97/example/ycb_demo.py
import bpy
import bpycv
import os
import glob
import random
example_data_dir = os.environ['BPY_EXAMPLE_DATA']
models = sorted(glob.glob(os.path.join(example_data_dir, "model", "*", "*.obj")))
cat_id_to_model_path = dict(enumerate(sorted(models), 1))
distractors = sorted(glob.glob(os.path.join(example_data_dir, "distractor", "*.obj")))
bpycv.clear_all()
bpy.context.scene.frame_set(1)
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
# A transparency stage for holding rigid body
stage = bpycv.add_stage(transparency=True)
bpycv.set_cam_pose(cam_radius=1, cam_deg=45)
hdri_dir = os.path.join(example_data_dir, "background_and_light")
hdri_manager = bpycv.HdriManager(
hdri_dir=hdri_dir, download=False
) # if download is True, will auto download .hdr file from HDRI Haven
hdri_path = hdri_manager.sample()
bpycv.load_hdri_world(hdri_path, random_rotate_z=True)
# load 5 objects
for index in range(5):
cat_id = random.choice(list(cat_id_to_model_path))
model_path = cat_id_to_model_path[cat_id]
obj = bpycv.load_obj(model_path)
obj.location = (
random.uniform(-0.2, 0.2),
random.uniform(-0.2, 0.2),
random.uniform(0.1, 0.3),
)
obj.rotation_euler = [random.uniform(-3.1415, 3.1415) for _ in range(3)]
# set each instance a unique inst_id, which is used to generate instance annotation.
obj["inst_id"] = cat_id * 1000 + index
with bpycv.activate_obj(obj):
bpy.ops.rigidbody.object_add()
# load 6 distractors
for index in range(6):
distractor_path = random.choice(distractors)
target_size = random.uniform(0.1, 0.3)
distractor = bpycv.load_distractor(distractor_path, target_size=target_size)
distractor.location = (
random.uniform(-0.2, 0.2),
random.uniform(-0.2, 0.2),
random.uniform(0.1, 0.3),
)
distractor.rotation_euler = [random.uniform(-3.1415, 3.1415) for _ in range(3)]
with bpycv.activate_obj(distractor):
bpy.ops.rigidbody.object_add()
# run pyhsic engine for 20 frames
for i in range(20):
bpy.context.scene.frame_set(bpy.context.scene.frame_current + 1)
# 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.')

View file

@ -0,0 +1,62 @@
{ lib
, buildPythonPackage
, fetchPypi
, fetchFromGitHub
, fetchurl
, writeText
, blender
, minexr
, beautifulsoup4
, zcs
, requests
, opencv3
, boxx
}:
buildPythonPackage rec {
pname = "bpycv";
version = "0.2.43";
src = fetchPypi {
inherit pname version;
sha256 = "sha256-6LXhKuNkX3yKeZARLXmOVNAUQhJghtzKhnszJ1G/a8U=";
};
propagatedBuildInputs = [
beautifulsoup4
minexr
zcs
requests
opencv3
boxx
];
postPatch = ''
sed -i 's/opencv-python//g' requirements.txt
'';
# pythonImportsCheck = [ "bpycv" ]; # this import depends on bpy that is only available inside blender
checkInputs = [ blender ];
checkPhase = let
bpycv_example_data = fetchFromGitHub {
owner = "DIYer22";
repo = "bpycv_example_data";
sha256 = "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
'';
meta = with lib; {
description = "Computer vision utils for Blender";
homepage = "https://github.com/DIYer22/bpycv";
license = licenses.mit;
maintainers = with maintainers; [ lucasew ];
};
}

View file

@ -0,0 +1,31 @@
{ lib
, buildPythonPackage
, fetchFromGitHub
, pytestCheckHook
, numpy
, pillow
}:
buildPythonPackage rec {
pname = "minexr";
version = "1.0.1";
src = fetchFromGitHub {
owner = "cheind";
repo = "py-minexr";
rev = "v${version}";
sha256 = "sha256-Om67ttAHxu7C3IwPB+JHYi78E9qBi1E6layMVg4+S3M=";
};
propagatedBuildInputs = [ numpy ];
pythonImportsCheck = [ "minexr" ];
checkInputs = [ pytestCheckHook pillow ];
meta = with lib; {
description = "Minimal, standalone OpenEXR reader for single-part, uncompressed scan line files.";
homepage = "https://github.com/cheind/py-minexr";
license = licenses.mit;
maintainers = with maintainers; [ lucasew ];
};
}

View file

@ -0,0 +1,34 @@
{ lib
, buildPythonPackage
, fetchPypi
, numpy
, nose
}:
buildPythonPackage rec {
pname = "pyquaternion";
version = "0.9.9";
src = fetchPypi {
inherit pname version;
sha256 = "sha256-sfYa8hnLL+lmtft5oZISTy5jo/end6w8rfKVexqBvqg=";
};
# The VERSION.txt file is required for setup.py
# See: https://github.com/KieranWynn/pyquaternion/blob/master/setup.py#L14-L15
postPatch = ''
echo "${version}" > VERSION.txt
'';
propagatedBuildInputs = [ numpy ];
checkInputs = [ nose ];
pythonImportsCheck = [ "pyquaternion" ];
meta = with lib; {
description = "Library for representing and using quaternions.";
homepage = "http://kieranwynn.github.io/pyquaternion/";
license = licenses.mit;
maintainers = with maintainers; [ lucasew ];
};
}

View file

@ -0,0 +1,32 @@
{ lib
, buildPythonPackage
, fetchFromGitHub
, python
, pyyaml
}:
buildPythonPackage rec {
pname = "yacs";
version = "0.1.8";
src = fetchFromGitHub {
owner = "rbgirshick";
repo = "yacs";
rev = "v${version}";
sha256 = "sha256-nO8FL4tTkfTthXYXxXORLieFwvn780DDxfrxC9EUUJ0=";
};
propagatedBuildInputs = [ pyyaml ];
pythonImportsCheck = [ "yacs" ];
checkPhase = ''
${python.interpreter} yacs/tests.py
'';
meta = with lib; {
description = "Yet Another Configuration System";
homepage = "https://github.com/rbgirshick/yacs";
license = licenses.apsl20;
maintainers = with maintainers; [ lucasew ];
};
}

View file

@ -0,0 +1,33 @@
{ lib
, buildPythonPackage
, fetchPypi
, python
, yacs
, boxx
}:
buildPythonPackage rec {
pname = "zcs";
version = "0.1.17";
src = fetchPypi {
inherit pname version;
sha256 = "sha256-ZoQgAaJy3kKHLljyKA0Oo/D1kefE8X9FlsGDSNt1nPw=";
};
propagatedBuildInputs = [ yacs ];
pythonImportsCheck = [ "zcs" ];
checkInputs = [ boxx ];
checkPhase = ''
${python.interpreter} test/test_zcs.py
'';
meta = with lib; {
description = "A flexible powerful configuration system which takes advantage of both argparse and yacs";
homepage = "https://github.com/DIYer22/zcs";
license = licenses.mit;
maintainers = with maintainers; [ lucasew ];
};
}

View file

@ -24507,6 +24507,8 @@ with pkgs;
inherit (darwin.apple_sdk.frameworks) Cocoa CoreGraphics ForceFeedback OpenAL OpenGL;
};
blender-with-packages = callPackage ../applications/misc/blender/wrapper.nix {};
blflash = callPackage ../tools/misc/blflash { };
blogc = callPackage ../applications/misc/blogc { };

View file

@ -1132,6 +1132,8 @@ in {
bayespy = callPackage ../development/python-modules/bayespy { };
bbox = callPackage ../development/python-modules/bbox { };
bc-python-hcl2 = callPackage ../development/python-modules/bc-python-hcl2 { };
bcdoc = callPackage ../development/python-modules/bcdoc { };
@ -1304,6 +1306,10 @@ in {
bottleneck = callPackage ../development/python-modules/bottleneck { };
boxx = callPackage ../development/python-modules/boxx { };
bpycv = callPackage ../development/python-modules/bpycv {};
bpython = callPackage ../development/python-modules/bpython { };
braceexpand = callPackage ../development/python-modules/braceexpand { };
@ -4975,6 +4981,8 @@ in {
millheater = callPackage ../development/python-modules/millheater { };
minexr = callPackage ../development/python-modules/minexr { };
miniaudio = callPackage ../development/python-modules/miniaudio { };
minidb = callPackage ../development/python-modules/minidb { };
@ -7251,6 +7259,8 @@ in {
pyquery = callPackage ../development/python-modules/pyquery { };
pyquaternion = callPackage ../development/python-modules/pyquaternion { };
pyquil = callPackage ../development/python-modules/pyquil { };
pyrabbit2 = callPackage ../development/python-modules/pyrabbit2 { };
@ -10562,6 +10572,8 @@ in {
yattag = callPackage ../development/python-modules/yattag { };
yacs = callPackage ../development/python-modules/yacs { };
ydiff = callPackage ../development/python-modules/ydiff { };
yeelight = callPackage ../development/python-modules/yeelight { };
@ -10618,6 +10630,8 @@ in {
zconfig = callPackage ../development/python-modules/zconfig { };
zcs = callPackage ../development/python-modules/zcs { };
zdaemon = callPackage ../development/python-modules/zdaemon { };
zeek = toPythonModule (pkgs.zeek.override {