Skip to content

MINIFICPP-989 - Motion detect for a set of captured frames#627

Closed
nghiaxlee wants to merge 1 commit intoapache:masterfrom
nghiaxlee:MINIFICPP-989
Closed

MINIFICPP-989 - Motion detect for a set of captured frames#627
nghiaxlee wants to merge 1 commit intoapache:masterfrom
nghiaxlee:MINIFICPP-989

Conversation

@nghiaxlee
Copy link
Copy Markdown
Contributor

Thank you for submitting a contribution to Apache NiFi - MiNiFi C++.

In order to streamline the review of the contribution we ask you
to ensure the following steps have been taken:

For all changes:

  • Is there a JIRA ticket associated with this PR? Is it referenced
    in the commit message?

  • Does your PR title start with MINIFICPP-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.

  • Has your PR been rebased against the latest commit within the target branch (typically master)?

  • Is your initial contribution a single, squashed commit?

For code changes:

  • If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under ASF 2.0?
  • If applicable, have you updated the LICENSE file?
  • If applicable, have you updated the NOTICE file?

For documentation related changes:

  • Have you ensured that format looks appropriate for the output in which it is rendered?

Note:

Please ensure that once the PR is submitted, you check travis-ci for build issues and submit an update to your PR as soon as possible.

if (ret != stream->getSize()) {
throw std::runtime_error("ImageReadCallback failed to fully read flow file input stream");
}
*image_mat_ = cv::imdecode(image_buf_, -1);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Who is responsible for the lifetime of this resource?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It will be released outside onTrigger scope. The pointer points to a cv::Mat object in onTrigger, and the CallBack also in onTrigger.

namespace apache {
namespace nifi {
namespace minifi {
namespace processors {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

As these are only callbacks used for opencv, could you add them to a dirrent namepsace? Opencv is fine imho.

namespace minifi {
namespace processors {

core::Property MotionDetector::ImageEncoding( // NOLINT
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please avoid nolint in such cases!
There is a core::propertybuilder class, used by a lot of MiNiFi processors, check those examples please!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I know, I changed one but not all of them, will change all in the next commit.

std::set<core::Relationship> relationships;
relationships.insert(Success);
relationships.insert(Failure);
setSupportedRelationships(std::move(relationships));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

setSupportedRelationships({Success, Failure});

Is a bit less complicated way of doing the same :)

logger_->log_info("Background is missing, update and exit.");
cv::cvtColor(frame, bg_img_, cv::COLOR_BGR2GRAY);
cv::GaussianBlur(bg_img_, bg_img_, cv::Size(21, 21), 0, 0);
// cv::equalizeHist(bg_img_, bg_img_);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we need it?

session->write(flow_file, &write_cb);
session->write(diff_file, &write_cb2);
session->transfer(flow_file, Success);
session->transfer(diff_file, Success);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not sure if these two should be transferred to the same relationship. Do we need the original FF anyway?

Copy link
Copy Markdown
Contributor

@arpadboda arpadboda left a comment

Choose a reason for hiding this comment

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

Some minor comments, mostly looks good.


if (context->getProperty(BackgroundFrame.getName(), value) && !value.empty()) {
bg_img_ = cv::imread(value, cv::IMREAD_GRAYSCALE);
double scale = 500.0 / bg_img_.size().width;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this a value good for all scenarios we can imagine or shall we make it configurable?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

IMO, this should work for all scenarios, the main point is balance between computation time and accuracy

bool update_bg_;

// Background & Foreground seperation.
// std::vector<cv::Mat> history;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Are these parts of some features not ready yet or just leftovers?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

They are for "Background & Foreground extraction" features that I wanted earlier. However, after second thought, I think I will create a new processor for that later, since it can be useful itself.

Copy link
Copy Markdown
Contributor

@arpadboda arpadboda left a comment

Choose a reason for hiding this comment

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

Looks good, thanks! Will merge soon.

@arpadboda arpadboda closed this in 72f92fa Sep 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants