-
Notifications
You must be signed in to change notification settings - Fork 6
Pranay Code Review #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 30 commits
0e68809
219ebef
c57f8b6
6fd1b89
f4f3682
988772c
434bcc5
c53e035
2dede26
242a3f5
829f038
8609a99
18f2a4c
541ba35
d81b2d8
c7a0260
d0c46aa
ab30969
7bcb70b
f76f67b
a46ab1e
8d7db64
693a786
e8bd9c5
5ebe19d
ccf86c9
c0426df
244ed09
2c04eff
207128c
883bf72
6702dcd
3a70b76
0dcec19
fe9f502
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| #ifndef LIGHTDB_PYTHON_GREYSCALE_H | ||
| #define LIGHTDB_PYTHON_GREYSCALE_H | ||
|
mundrapranay marked this conversation as resolved.
Outdated
|
||
|
|
||
| #include "Functor.h" | ||
|
|
||
|
|
||
| namespace lightdb::python { | ||
| class PythonGreyscale : public lightdb::functor::unaryfunctor { | ||
| class CPU : public lightdb::functor::unaryfunction { | ||
| public: | ||
| explicit CPU(PyObject* const callable, const bool deterministic=true) | ||
| : lightdb::functor::unaryfunction(lightdb::physical::DeviceType::CPU, | ||
| lightdb::Codec::raw(), | ||
| deterministic), | ||
| callable_(callable) | ||
| { | ||
| CHECK_NOTNULL(callable); | ||
| callable->ob_refcnt++; | ||
|
mundrapranay marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| void Allocate(const unsigned int height, const unsigned int width, const unsigned int channels) { | ||
| if (rgbSize_ != channels * height * width) { | ||
| frameSize_ = height * width; | ||
| rgbSize_ = channels * frameSize_; | ||
| rgb_.resize(rgbSize_); | ||
| mask_.resize(rgbSize_); | ||
|
mundrapranay marked this conversation as resolved.
Outdated
|
||
| } | ||
| } | ||
|
|
||
| lightdb::shared_reference<lightdb::LightField> operator()(lightdb::LightField& field) override; | ||
|
|
||
| private: | ||
| PyObject* const callable_; | ||
| unsigned int kernelSize_; | ||
|
mundrapranay marked this conversation as resolved.
Outdated
|
||
| unsigned int rgbSize_; | ||
| unsigned int frameSize_; | ||
| std::vector<unsigned char> rgb_; | ||
| std::vector<unsigned char> mask_; | ||
| }; | ||
|
|
||
| public: | ||
| explicit PythonGreyscale(PyObject* const callable, const bool deterministic=true) : functor::unaryfunctor("Greyscale", CPU(callable, deterministic)) {} | ||
|
mundrapranay marked this conversation as resolved.
Outdated
|
||
| }; | ||
|
|
||
| } | ||
|
|
||
| #endif //LIGHTDB__PYTHON_GREYSCALE_H | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| #include <boost/python/numpy.hpp> | ||
| #include <iostream> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Project then dependencies then system includes (I think this is in Google's C++ style guide) |
||
| #include <vector> | ||
| #include "PythonGreyscale.h" | ||
| #include "npp.h" | ||
| #include "ipp.h" | ||
| #include "Format.h" | ||
|
|
||
| namespace np = boost::python::numpy; | ||
|
|
||
| namespace lightdb::python { | ||
| shared_reference <LightField> PythonGreyscale::CPU::operator()(LightField &input) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can |
||
| np::initialize(); | ||
| const auto channels = 3u; | ||
| auto &data = dynamic_cast<lightdb::physical::CPUDecodedFrameData&>(input); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. const?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add precondition check on input being of the right type |
||
| lightdb::physical::CPUDecodedFrameData output(data.configuration(), data.geometry()); | ||
|
|
||
| for(auto& frame: data.frames()) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. probably const |
||
| Allocate(frame->height(), frame->width(), channels); | ||
| IppiSize size{static_cast<int>(frame->width()), static_cast<int>(frame->height())}; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. const |
||
| auto y_in = reinterpret_cast<const unsigned char*>(frame->data().data()); | ||
| auto uv_in = y_in + frameSize_; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check frame format before assuming NV12; throw if in an unexpected form |
||
| output.frames().emplace_back(LocalFrameReference::make<LocalFrame>(*frame, frame->data().size(), lightdb::video::Format::nv12())); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move NV12->RGB to a dedicated function in case we support other format conversions
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe use frame->format() instead of hardcoding format? |
||
| auto y_out = output.frames().back()->data().data(); | ||
| auto uv_out = y_out + frameSize_; | ||
|
|
||
| // NV12 -> RGB | ||
| CHECK_EQ(ippiYCbCr420ToRGB_8u_P2C3R((Ipp8u*)y_in, frame->width(), (Ipp8u*)uv_in, frame->width(), rgb_.data(), channels * frame->width(), size), ippStsNoErr); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reinterpret_cast |
||
|
|
||
| // RGB --> Numpy | ||
| np::dtype dtype = np::dtype::get_builtin<unsigned char>(); | ||
| np::ndarray py_array = np::from_data( | ||
| rgb_.data(), | ||
| dtype, | ||
| boost::python::make_tuple(channels, frame->width(), frame->height()), | ||
| boost::python::make_tuple(1 , sizeof(unsigned char) * channels, sizeof(unsigned char) * channels * frame->width()), | ||
| boost::python::object()); | ||
|
|
||
| np::ndarray swap = py_array.transpose(); | ||
| boost::python::call<void>(callable_, swap); | ||
|
|
||
| // RGB -> NV12 | ||
| CHECK_EQ(ippiRGBToYCbCr420_8u_C3P2R(rgb_.data(), channels * frame->width(), (Ipp8u*)y_out, frame->width(), (Ipp8u*)uv_out, frame->width(), size), ippStsNoErr); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reinterpret_cast |
||
| } | ||
| return output; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,13 @@ | ||
| import pytest | ||
| import pylightdb as db | ||
| import pylightdb | ||
| from pylightdb import * | ||
|
|
||
| def scan_test(): | ||
| PythonLightField pydb = db.Scan() | ||
| x = SpatiotemporalRange(0,0) | ||
| y = SpatiotemporalRange(0,0) | ||
| z = SpatiotemporalRange(0,0) | ||
| vol = Volume(x,y,z) | ||
| geo = EquirectangularGeometry(2,1) | ||
| env = LocalEnvironment() | ||
| optimizer = HeuristicOptimizer(env) | ||
| coordinator = Coordinator() | ||
| query = Load("/home/pranay99/lightdb/test/resources/test-pattern.h264", {"Volume":vol, "Projection":geo}).Save("/home/pranay99/test.mp4") | ||
| coordinator.Execute(query.query(), optimizer) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import pylightdb | ||
| import numpy as np | ||
| import cv2 as cv | ||
| from PIL import Image | ||
| from pylightdb import * | ||
|
|
||
| x = SpatiotemporalRange(0,0) | ||
| y = SpatiotemporalRange(0,0) | ||
| z = SpatiotemporalRange(0,0) | ||
| vol = Volume(x,y,z) | ||
| geo = EquirectangularGeometry(0,0) | ||
| env = LocalEnvironment() | ||
| optimizer = HeuristicOptimizer(env) | ||
| coordinator = Coordinator() | ||
| def rgb2gray(rgb): | ||
| rgb_weights = [0.2989, 0.5870, 0.1140] | ||
| grayscale_image = np.dot(rgb[...,:3], rgb_weights) | ||
| rgb[:,:,:] = grayscale_image[:,:,np.newaxis] | ||
| return rgb | ||
| grey = PythonGreyscale(rgb2gray) | ||
| query = Load("/home/pranay99/colorsrc.h264", {"Volume":vol, "Projection":geo}).Map(grey).Save("/home/pranay99/lambdaTest.h264") | ||
| coordinator.Execute(query.query(), optimizer) |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,10 @@ get_property(LIGHTDB_INCLUDES DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INC | |
| string(REPLACE ";" "|" LIGHTDB_INCLUDES_STRING "${LIGHTDB_INCLUDES}") | ||
|
|
||
| foreach(LIGHTDB_PLUGIN_DIR ${LIGHTDB_PLUGIN_DIRS}) | ||
| message("Lightdb plugin dir: ${LIGHTDB_PLUGIN_DIR}") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ? |
||
| message("CMAKE_CURRENT_BINARY_DIR: ${CMAKE_CURRENT_BINARY_DIR}") | ||
| message("LIGHTDB_PLUGIN_DIR: ${LIGHTDB_PLUGIN_DIR}") | ||
| message("CMAKE_SOURCE_DIR: ${CMAKE_SOURCE_DIR}") | ||
| if (IS_DIRECTORY ${LIGHTDB_PLUGIN_DIR}) | ||
| get_filename_component(LIGHTDB_PLUGIN_NAME ${LIGHTDB_PLUGIN_DIR} NAME_WE) | ||
| string(TOLOWER "${LIGHTDB_PLUGIN_DIR}/cmake-build-${CMAKE_BUILD_TYPE}" LIGHTDB_PLUGIN_BINARY_DIR) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -86,6 +86,21 @@ TEST_F(SelectionTestFixture, testSelectPhi) { | |
| EXPECT_EQ(remove(Resources.out.hevc), 0); | ||
| } | ||
|
|
||
| TEST_F(SelectionTestFixture, testSelectPhi2) { | ||
| auto query = Load("/home/maureen/lightdb/cmake-build-debug-remote/test/resources/red10/stream0.h264") | ||
| .Select(PhiRange{0, rational_times_real({1, 4}, PI)}) | ||
| .Encode() | ||
| .Save("/home/maureen/encoded0.hevc"); | ||
|
|
||
| Coordinator().execute(query); | ||
|
|
||
| EXPECT_VIDEO_VALID(Resources.out.hevc); | ||
| EXPECT_VIDEO_FRAMES(Resources.out.hevc, Resources.red10.frames); | ||
| EXPECT_VIDEO_RESOLUTION(Resources.out.hevc, Resources.red10.height / 4, Resources.red10.width); | ||
| EXPECT_VIDEO_RED(Resources.out.hevc); | ||
| EXPECT_EQ(remove(Resources.out.hevc), 0); | ||
| } | ||
|
|
||
| TEST_F(SelectionTestFixture, testSelectTheta) { | ||
| REQUIRE_GPU(); | ||
|
|
||
|
|
@@ -156,6 +171,15 @@ TEST_F(SelectionTestFixture, testTemporalThetaSelect) { | |
| EXPECT_EQ(remove(Resources.out.hevc), 0); | ||
| } | ||
|
|
||
| TEST_F(SelectionTestFixture, testPythonQuery) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ? |
||
| auto query = Load("/home/maureen/lightdb/test/resources/tiles/tile-6.hevc") | ||
| .Select(PhiRange{0, rational_times_real({3, 4}, PI)}) | ||
| .Encode() | ||
| .Save("/home/maureen/selected-tile-6-test.hevc"); | ||
|
|
||
| Coordinator().execute(query); | ||
| } | ||
|
|
||
| TEST_F(SelectionTestFixture, testDegenerateTimeSelect) { | ||
| REQUIRE_GPU(); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,7 +27,7 @@ TEST_F(UDFTestFixture, testGreyscale) { | |
| auto query = Scan(Resources.red10.name) | ||
| .Map(lightdb::Greyscale) | ||
| .Encode() | ||
| .Save(Resources.out.hevc); | ||
| .Save("/home/maureen/grey_test.hevc"); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ? |
||
|
|
||
| Coordinator().execute(query); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove hardcoded paths