0

I have attached the code below. In this code, I want to write a section to get the binary LSB values from the RGB value of frames. Frames - The video is fragmented into respective video frames

import numpy as np
import cv2 as cv

vidcap = cv.VideoCapture("video.mp4")
if not vidcap.isOpened():
    print("Cannot open camera")
    exit()
while True:
    # Capture frame-by-frame
    ret, frame = vidcap.read()
     # -------------------------------------------------------------> step 2 - split
    # if frame is read correctly ret is True
    if not ret:
        print("Can't receive frame (stream end?). Exiting ...")
        break
    # Our operations on the frame come here
    gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
    print(gray)
    # Display the resulting frame
    cv.imshow('frame', gray)
    if cv.waitKey(1) == ord('q'):
        break
# When everything done, release the capture
vidcap.release()
cv.destroyAllWindows()
Heeya
  • 11
  • 3
  • What is your *frames* looks like? You may find this helpful - https://stackoverflow.com/questions/21341338/ – Daniel Hao Sep 03 '22 at 11:43
  • `frame` is a numpy array, most likely 3d, i.e., width x height x 3 (the width and height might be switched around, I don't remember). Iterating over all its elements is trivial. To get the binary **string** of a number, use `bin()`. But you can directly extract and modify bits from integers using [bitwise operations](https://en.wikipedia.org/wiki/Bitwise_operation). For example, [extracting](https://stackoverflow.com/questions/45220959/python-how-do-i-extract-specific-bits-from-a-byte) and [setting](https://stackoverflow.com/questions/12173774/how-to-modify-bits-in-an-integer) a bit. – Reti43 Sep 03 '22 at 13:29
  • Also be careful that the numpy array stores the colours of a pixel in BGR order. That's the 3 in the `width x height x 3` size. – Reti43 Sep 03 '22 at 13:34
  • @Reti43 I have converted the 3d frame into a 2d numpy array but I am getting TypeError: 'int' object is not iterable. I have attached that part of the code below: width, height, d=frame.shape print("reshaped...") frame_reshp = frame.reshape(width*height,3) w, h = frame_reshp.shape for i in h: for j in w: print(frame_reshp[i][j]) – Heeya Sep 03 '22 at 17:26

0 Answers0