Skip to content
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

Basic Video Support #74

Merged
merged 4 commits into from
Jan 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,28 @@ def buildServer(env):
'src/QueryHandler.cc',
'src/QueryMessage.cc',
'src/CommunicationManager.cc',
'src/ExceptionsCommand.cc',
'src/PMGDQuery.cc',
'src/SearchExpression.cc',
'src/PMGDIterators.cc',
'src/PMGDQueryHandler.cc',
'src/RSCommand.cc',
'src/ImageCommand.cc',
'src/ExceptionsCommand.cc',
'src/DescriptorsManager.cc',
'src/DescriptorsCommand.cc',
'src/BoundingBoxCommand.cc',
'src/VideoCommand.cc',
]

vdms = env.Program('vdms', vdms_server_files)
env.Program('vdms', vdms_server_files)
vishakha041 marked this conversation as resolved.
Show resolved Hide resolved

# Set INTEL_PATH. First check arguments, then enviroment, then default
if ARGUMENTS.get('INTEL_PATH', '') != '':
intel_path = ARGUMENTS.get("INTEL_PATH", '')
intel_path = ARGUMENTS.get("INTEL_PATH", '')
elif os.environ.get('INTEL_PATH', '') != '':
intel_path = os.environ.get('INTEL_PATH', '')
intel_path = os.environ.get('INTEL_PATH', '')
else:
intel_path = os.getcwd()
intel_path = os.getcwd()

# Enviroment use by all the builds
env = Environment(CXXFLAGS="-std=c++11 -O3")
Expand All @@ -66,6 +67,6 @@ SConscript(os.path.join('utils', 'SConscript'), exports=['env'])
SConscript(os.path.join('client/cpp','SConscript'), exports=['env'])

if GetOption('no-server'):
buildServer(env)
# Build tests only if server is built
SConscript(os.path.join('tests', 'SConscript'), exports=['env'])
buildServer(env)
# Build tests only if server is built
SConscript(os.path.join('tests', 'SConscript'), exports=['env'])
10 changes: 5 additions & 5 deletions src/BoundingBoxCommand.cc
Original file line number Diff line number Diff line change
Expand Up @@ -316,19 +316,19 @@ Json::Value FindBoundingBox::construct_responses(
get_value<int>(coords, "w"),
get_value<int>(coords, "h")));

VCL::ImageFormat format =
img.get_image_format() != VCL::TDB ?
img.get_image_format() : VCL::PNG;
VCL::Image::Format format =
vishakha041 marked this conversation as resolved.
Show resolved Hide resolved
img.get_image_format() != VCL::Image::Format::TDB ?
img.get_image_format() : VCL::Image::Format::PNG;

if (cmd.isMember("format")) {
std::string requested_format =
get_value<std::string>(cmd, "format");

if (requested_format == "png") {
format = VCL::PNG;
format = VCL::Image::Format::PNG;
}
else if(requested_format == "jpg") {
format = VCL::JPG;
format = VCL::Image::Format::JPG;
}
}

Expand Down
20 changes: 10 additions & 10 deletions src/ImageCommand.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,21 +103,21 @@ int AddImage::construct_protobuf(PMGDQuery& query,
}

std::string img_root = _storage_tdb;
VCL::ImageFormat vcl_format = VCL::TDB;
VCL::Image::Format vcl_format = VCL::Image::Format::TDB;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this file could totally use a
using namespace VCL; IT appears often enough to avoid doing VCL:: everywhere

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. For now we just update the changes in the enums. We can change namespacing in a future refactor, I already have some other things in mind that we can do better.


std::string format = get_value<std::string>(cmd, "format", "");
if (cmd.isMember("format")) {
std::string format = get_value<std::string>(cmd, "format");

if (format == "png") {
vcl_format = VCL::PNG;
vcl_format = VCL::Image::Format::PNG;
img_root = _storage_png;
}
else if (format == "tdb") {
vcl_format = VCL::TDB;
vcl_format = VCL::Image::Format::TDB;
img_root = _storage_tdb;
}
else if (format == "jpg") {
vcl_format = VCL::JPG;
vcl_format = VCL::Image::Format::JPG;
img_root = _storage_jpg;
}
else {
Expand All @@ -127,7 +127,7 @@ int AddImage::construct_protobuf(PMGDQuery& query,
}
}

std::string file_name = img.create_unique(img_root, vcl_format);
std::string file_name = VCL::create_unique(img_root, format);

// Modifiyng the existing properties that the user gives
// is a good option to make the AddNode more simple.
Expand Down Expand Up @@ -267,18 +267,18 @@ Json::Value FindImage::construct_responses(
// We will return the image in the format the user
// request, or on its format in disk, except for the case
// of .tdb, where we will encode as png.
VCL::ImageFormat format = img.get_image_format() != VCL::TDB ?
img.get_image_format() : VCL::PNG;
VCL::Image::Format format = img.get_image_format() != VCL::Image::Format::TDB ?
img.get_image_format() : VCL::Image::Format::PNG;

if (cmd.isMember("format")) {
std::string requested_format =
get_value<std::string>(cmd, "format");

if (requested_format == "png") {
format = VCL::PNG;
format = VCL::Image::Format::PNG;
}
else if (requested_format == "jpg") {
format = VCL::JPG;
format = VCL::Image::Format::JPG;
}
else {
Json::Value return_error;
Expand Down
31 changes: 27 additions & 4 deletions src/QueryHandler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#include "ImageCommand.h"
#include "DescriptorsCommand.h"
#include "BoundingBoxCommand.h"
#include "VideoCommand.h"

#include "ExceptionsCommand.h"

#include "PMGDQuery.h"
Expand All @@ -61,21 +63,29 @@ void QueryHandler::init()

_rs_cmds["AddEntity"] = new AddEntity();
_rs_cmds["UpdateEntity"] = new UpdateEntity();
_rs_cmds["FindEntity"] = new FindEntity();

_rs_cmds["AddConnection"] = new AddConnection();
_rs_cmds["UpdateConnection"] = new UpdateConnection();
_rs_cmds["FindEntity"] = new FindEntity();
_rs_cmds["FindConnection"] = new FindConnection();

_rs_cmds["AddImage"] = new AddImage();
_rs_cmds["UpdateImage"] = new UpdateImage();
_rs_cmds["FindImage"] = new FindImage();

_rs_cmds["AddDescriptorSet"] = new AddDescriptorSet();
_rs_cmds["AddDescriptor"] = new AddDescriptor();
_rs_cmds["ClassifyDescriptor"] = new ClassifyDescriptor();
_rs_cmds["FindDescriptor"] = new FindDescriptor();
_rs_cmds["ClassifyDescriptor"] = new ClassifyDescriptor();

_rs_cmds["AddBoundingBox"] = new AddBoundingBox();
_rs_cmds["UpdateBoundingBox"] = new UpdateBoundingBox();
_rs_cmds["FindBoundingBox"] = new FindBoundingBox();

_rs_cmds["AddVideo"] = new AddVideo();
_rs_cmds["UpdateVideo"] = new UpdateVideo();
_rs_cmds["FindVideo"] = new FindVideo();

// Load the string containing the schema (api_schema/APISchema.h)
Json::Reader reader;
Json::Value api_schema;
Expand Down Expand Up @@ -239,12 +249,21 @@ int QueryHandler::parse_commands(const protobufs::queryMessage& proto_query,
return 0;
}

void QueryHandler::cleanup_query(const std::vector<std::string>& images)
// TODO create a better mechanism to cleanup queries that
// includes feature vectors and user-defined blobs
// For now, we do it for videos/images as a starting point.
void QueryHandler::cleanup_query(const std::vector<std::string>& images,
const std::vector<std::string>& videos)
{
for (auto& img_path : images) {
VCL::Image img(img_path);
img.delete_image();
}

for (auto& vid_path : videos) {
VCL::Video img(vid_path);
img.delete_video();
}
}

void QueryHandler::process_query(protobufs::queryMessage& proto_query,
Expand Down Expand Up @@ -272,11 +291,12 @@ void QueryHandler::process_query(protobufs::queryMessage& proto_query,
Json::Value cmd_result;
Json::Value cmd_current;
std::vector<std::string> images_log;
std::vector<std::string> videos_log;
std::vector<Json::Value> construct_results;

auto error = [&](Json::Value& res, Json::Value& failed_command)
{
cleanup_query(images_log);
cleanup_query(images_log, videos_log);
res["FailedCommand"] = failed_command;
json_responses.clear();
json_responses.append(res);
Expand Down Expand Up @@ -313,6 +333,9 @@ void QueryHandler::process_query(protobufs::queryMessage& proto_query,
if (cmd_result.isMember("image_added")) {
images_log.push_back(cmd_result["image_added"].asString());
}
if (cmd_result.isMember("video_added")) {
videos_log.push_back(cmd_result["video_added"].asString());
}

if (ret_code != 0) {
error(cmd_result, root[j]);
Expand Down
4 changes: 3 additions & 1 deletion src/QueryHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ typedef ::google::protobuf::RepeatedPtrField<std::string> BlobArray;
bool syntax_checker(const Json::Value &root, Json::Value& error);
int parse_commands(const protobufs::queryMessage& proto_query,
Json::Value& root);
void cleanup_query(const std::vector<std::string>& images);
void cleanup_query(const std::vector<std::string>& images,
const std::vector<std::string>& videos);

void process_query(protobufs::queryMessage& proto_query,
protobufs::queryMessage& response);

Expand Down
6 changes: 6 additions & 0 deletions src/VDMSConfig.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#define DEFAULT_PATH_PNG "png"
#define DEFAULT_PATH_TDB "tdb"
#define DEFAULT_PATH_BLOBS "blobs"
#define DEFAULT_PATH_VIDEOS "videos"
#define DEFAULT_PATH_DESCRIPTORS "descriptors"

using namespace VDMS;
Expand Down Expand Up @@ -176,6 +177,11 @@ void VDMSConfig::build_dirs()
path_blobs = get_string_value(PARAM_DB_BLOBS, path_blobs);
check_or_create(path_blobs);

// VIDEOS
path_videos = path_root + "/" + DEFAULT_PATH_VIDEOS;
path_videos = get_string_value(PARAM_DB_VIDEOS, path_videos);
check_or_create(path_videos);

// DESCRIPTORS
path_descriptors = path_root + "/" + DEFAULT_PATH_DESCRIPTORS;
path_descriptors = get_string_value(PARAM_DB_DESCRIPTORS, path_descriptors);
Expand Down
17 changes: 10 additions & 7 deletions src/VDMSConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#define PARAM_DB_JPG "jpg_path"
#define PARAM_DB_TDB "tdb_path"
#define PARAM_DB_BLOBS "blobs_path"
#define PARAM_DB_VIDEOS "videos_path"
#define PARAM_DB_DESCRIPTORS "descriptors_path"

#define PARAM_PMGD_NUM_ALLOCATORS "pmgd_num_allocators"
Expand Down Expand Up @@ -69,6 +70,7 @@ namespace VDMS{
std::string path_jpg;
std::string path_tdb;
std::string path_blobs;
std::string path_videos;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The naming of these variables is a little funny. I realize I am late on that comment but sometimes it is path_* and sometimes *_path

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we will keep them consistent for this commit. it is consistent on what it is for the user and what it is internal, so I am ok with the names.

std::string path_descriptors;

VDMSConfig(std::string config_file);
Expand All @@ -80,13 +82,14 @@ namespace VDMS{
public:
int get_int_value(std::string val, int def);
std::string get_string_value(std::string val, std::string def);
std::string get_path_root() {return path_root;}
std::string get_path_pmgd() {return path_pmgd;}
std::string get_path_jpg() {return path_jpg;}
std::string get_path_png() {return path_png;}
std::string get_path_tdb() {return path_tdb;}
std::string get_path_blobs() {return path_blobs;}
std::string get_path_descriptors() {return path_descriptors;}
const std::string& get_path_root() {return path_root;}
const std::string& get_path_pmgd() {return path_pmgd;}
const std::string& get_path_jpg() {return path_jpg;}
const std::string& get_path_png() {return path_png;}
const std::string& get_path_tdb() {return path_tdb;}
const std::string& get_path_blobs() {return path_blobs;}
const std::string& get_path_videos(){return path_videos;}
const std::string& get_path_descriptors() {return path_descriptors;}
};

}; // vdms namespace
Loading