Skip to content

Instantly share code, notes, and snippets.

@phrocker
Last active June 27, 2019 00:22
Show Gist options
  • Select an option

  • Save phrocker/57080f9e3f52c5b7a984c21e39b0d195 to your computer and use it in GitHub Desktop.

Select an option

Save phrocker/57080f9e3f52c5b7a984c21e39b0d195 to your computer and use it in GitHub Desktop.
# 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.
"""
Install opencv-python
"""
import numpy as np
import cv2
import sys
import codecs
def describe(processor):
processor.setDescription("Runs haar cascaade.")
def onInitialize(processor):
# is required,
processor.addProperty("Path","Path to XML.","", True, False)
class ContentExtract(object):
def __init__(self):
self.content = None
def process(self, input_stream):
self.content = input_stream.read()
return len(self.content)
def onTrigger(context, session):
flow_file = session.get()
if flow_file is not None:
filename = context.getProperty("Path")
face_cascade = cv2.CascadeClassifier(filename)
imageextractor = ContentExtract()
session.read(flow_file,imageextractor)
nparr = np.fromstring(imageextractor.content, np.uint8)
img_np = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
gray = cv2.cvtColor(img_np, cv2.COLOR_BGR2GRAY)
# Detects faces of different sizes in the input image
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
if sys.getsizeof(faces) > 0:
flow_file.addAttribute("faces",str(sys.getsizeof(faces)))
session.transfer(flow_file, REL_SUCCESS)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment