node-opencv icon indicating copy to clipboard operation
node-opencv copied to clipboard

Applying a filter to a ROI

Open policevideorequests opened this issue 10 years ago • 1 comments

My objective is to blur faces in frames of video in parallel. I'm using node-opencv so that I can use OpenCV on AWS Lambda. I have not been able to detrimine the node-opencv equivalent of the following that is written in Python:

for (x, y, w, h) in faces:
    sub_face = image[y:y+h, x:x+w]
    # apply a gaussian blur on this new recangle image
    sub_face = cv2.GaussianBlur(sub_face,(23, 23), 30)
    # merge this blurry rectangle to our final image
    result_image[y:y+sub_face.shape[0], x:x+sub_face.shape[1]] = sub_face

The most I've gotten is saving a new image that is just the face blurred.

  var im2 = im.roi(face.x, face.y, face.width, face.height);
  im2.gaussianBlur([23,23], 30);
  im2.save('./tmp/face-detection-rectangle.png');

How do I save the blurred face to original image?

policevideorequests avatar Apr 17 '15 15:04 policevideorequests

Have you tried ?

im.roi(face.x, face.y, face.width, face.height).gaussianBlur([23, 23], 30);

Spope avatar Jul 20 '16 14:07 Spope