nifi-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [nifi-minifi-cpp] nghiaxlee commented on a change in pull request #627: MINIFICPP-989 - Motion detect for a set of captured frames
Date Tue, 10 Sep 2019 12:48:44 GMT
nghiaxlee commented on a change in pull request #627: MINIFICPP-989 - Motion detect for a set
of captured frames
URL: https://github.com/apache/nifi-minifi-cpp/pull/627#discussion_r322722190
 
 

 ##########
 File path: extensions/opencv/MotionDetector.cpp
 ##########
 @@ -0,0 +1,222 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "MotionDetector.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace processors {
+
+core::Property MotionDetector::ImageEncoding(
+    core::PropertyBuilder::createProperty("Image Encoding")
+        ->withDescription("The encoding that should be applied the the frame images captured
from the RTSP stream")
+        ->isRequired(true)
+        ->withAllowableValues<std::string>({".jpg", ".png"})
+        ->withDefaultValue(".jpg")->build());
+core::Property MotionDetector::MinInterestArea(
+    core::PropertyBuilder::createProperty("Minimum Area")
+        ->withDescription("We only consider the movement regions with area greater than
this.")
+        ->isRequired(true)
+        ->withDefaultValue<uint32_t>(100)->build());
+core::Property MotionDetector::Threshold(
+    core::PropertyBuilder::createProperty("Threshold for segmentation")
+        ->withDescription("Pixel greater than this will be white, otherwise black.")
+        ->isRequired(true)
+        ->withDefaultValue<uint32_t>(42)->build());
+core::Property MotionDetector::BackgroundFrame(
+    core::PropertyBuilder::createProperty("Path to background frame")
+        ->withDescription("If not provided then the processor will take the first input
frame as background")->build());
+core::Property MotionDetector::DilateIter(
+    core::PropertyBuilder::createProperty("Dilate iteration")
+        ->withDescription("For image processing")
+        ->isRequired(true)
+        ->withDefaultValue<uint32_t>(10)->build());
+core::Property MotionDetector::PrevAsBackground(
+    core::PropertyBuilder::createProperty("Previous frame as Background")
+        ->withDescription("Whether or not detect motion between 2 consecutive frames (yes/no)")
+        ->isRequired(false)
+        ->withAllowableValues<std::string>({"yes", "no"})
+        ->withDefaultValue("no")->build());
+
+core::Relationship MotionDetector::Success(  // NOLINT
+    "success",
+    "Successful to detect motion");
+core::Relationship MotionDetector::Failure(  // NOLINT
+    "failure",
+    "Failure to detect motion");
+
+void MotionDetector::initialize() {
+  std::set<core::Property> properties;
+  properties.insert(ImageEncoding);
+  properties.insert(MinInterestArea);
+  properties.insert(Threshold);
+  properties.insert(BackgroundFrame);
+  properties.insert(DilateIter);
+  properties.insert(PrevAsBackground);
+  setSupportedProperties(std::move(properties));
+
+  setSupportedRelationships({Success, Failure});
+}
+
+void MotionDetector::onSchedule(core::ProcessContext *context, core::ProcessSessionFactory
*sessionFactory) {
+  std::string value;
+
+  if (context->getProperty(ImageEncoding.getName(), value)) {
+    image_encoding_ = value;
+  }
+
+  if (context->getProperty(MinInterestArea.getName(), value)) {
+    core::Property::StringToInt(value, min_area_);
+  }
+
+  if (context->getProperty(Threshold.getName(), value)) {
+    core::Property::StringToInt(value, threshold_);
+  }
+
+  if (context->getProperty(DilateIter.getName(), value)) {
+    core::Property::StringToInt(value, dil_iter_);
+  }
+
+  if (context->getProperty(BackgroundFrame.getName(), value) && !value.empty())
{
+    bg_img_ = cv::imread(value, cv::IMREAD_GRAYSCALE);
+    double scale = 500.0 / bg_img_.size().width;
 
 Review comment:
   IMO, this should work for all scenarios, the main point is balance between computation
time and accuracy

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message