OpenCV and ReactNative

To clarify the scenario, giving some real examples, I’ve written a quick and simple code ( which I call client’s interface)
The sample starts a camera view to map and identify faces, using default cascade files. Once it finds it, it writes a frame as a PNG image to the filesystem.

So, during streaming capture, I’ve added colored frames (i.e. cv2.rectangle), arrows and messages, in order to guide the user to place the camera in the right position to facilitate image capturing.

That simple code was written in python in my desktop (just to illustrate the scenario to get a show the idea (even barely). Now I’d like to write a similar snippet in ReactNative

import numpy as np
import cv2
import sys
import random, string

faceCascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
eyeCascade = cv2.CascadeClassifier('haarcascade_eye_tree_eyeglasses.xml')

video_capture = cv2.VideoCapture(0)

cv2.namedWindow("Window", cv2.WINDOW_NORMAL)
cv2.resizeWindow('Window', 400, 400)

while True:
    ret, img = video_capture.read()
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    faces = faceCascade.detectMultiScale(gray, scaleFactor=1.3, minNeighbors=3, minSize=(30, 30))

   # print("[INFO] Found {0} Faces!".format(len(faces)))                                                                                                                                                
   for (x, y, w, h) in faces:
      cv2.rectangle(img, (x, y), (x+w, y+h), (255,0, 0), 2)
      roi_gray = gray[y:y+h, x:x+w]
      roi_color = img[y:y+h, x:x+w]
      eyes = eyeCascade.detectMultiScale(roi_gray)

      for (ex, ey, ew, eh) in eyes:
        cv2.rectangle(roi_color,(ex,ey),(ex+ew,ey+eh),(0,255,0), 2)

       if len(eyes) != 0:
          print("EYES", eyes)
          crop_img = img[y-99:y+h+99, x-36:x+w+36]
          if len(crop_img) != 0:
            letters = string.ascii_lowercase
            result_str = ''.join(random.choice(letters) for i in range(12))
            status = cv2.imwrite(result_str+".jpg", crop_img)
            print("[INFO] Image written to filesystem: ", status)


  cv2.imshow("Window",img)

  #This breaks on 'q' key                                                                                                                                                                              
  if cv2.waitKey(1) & 0xFF == ord('q'):
      break

video_capture.release() 
cv2.destroyAllWindows()