title: I want to do encryption on the faces detected in a video to preserve the identity. And then perform decryption on that video to reveal faces
body: <p>I am working in python and this is what I have tried-</p>
  
  <ul>
  <li>Used the OpenCv to identify the faces and obtain coordinates of faces in the video frame.</li>
  <li>Passed that frame and coordinates to encryption algo (I'm using chaotic masking) to perform encryption only inside the bounding box around the faces.</li>
  <li>Instead of saving these coordinates in an external file so that decryption can be performed on the encrypted area, I chose to mark the boundary box surrounding the faces in frame by modifying the value of pixels on the boundary of box to (0,0,0) and perform encryption inside the box.</li>
  <li><p>Then saving the encrypted frame in a directory so that I can obtain the new video from these frames with the help of following code-</p>
  
  <pre><code>pathIn= './frames/'
  pathOut = 'videonew.avi'
  fps = 15
  
  frame_array = []
  files = [f for f in os.listdir(pathIn) if isfile(join(pathIn, f))]
  #for sorting the frame names properly
  files.sort(key = lambda x: int(x[0:-4]))
  
  for i in range(len(files)):
      filename=pathIn + files[i]
      #reading each files
      img = cv2.imread(filename)
      height, width, layers = img.shape
      size = (width,height)
  
      #inserting the frames into an image array
      frame_array.append(img)
  out = cv2.VideoWriter(pathOut,cv2.VideoWriter_fourcc(*'DIVX'), fps, size)
  for i in range(len(frame_array)):
      # writing to a image array
      out.write(frame_array[i])
  out.release()
  </code></pre></li>
  <li><p>This works fine and created the video 'videonew.avi'. Now, to decrypt, I used following code to extract the frames from 'videonew.avi'.</p>
  
  <pre><code>vidcap = cv2.VideoCapture('videonew.avi')
  success,image = vidcap.read()
  count = 0
  path = os.getcwd() + "/test"
  os.chdir(path)
  while success:
    cv2.imwrite("%d.png" % count, image)     # save frame as PNGfile      
    success,image = vidcap.read()
    # print('Read a new frame: ', success)
    count += 1
  </code></pre></li>
  </ul>
  
  <p>But the extracted frames suffer some kind of compression and those (0,0,0) pixels that was marked on the boundary are not there (maybe changed). So, I can't perform decryption.
  Do you know why this is happening and how can I get frames without any loss of pixel ? 
  Or is there any other way to do this? I cannot store coordinates in external file because of some constraints offered by the project.</p>