I am working on a code to hide an image inside a video. For the same, I have broken down the video into its frames and extracted the RGB values of pixels of each frame. I have also written a code in python that extracts RGB values of the image. Now, I want to embed the image inside the video. For this I want to use LSB approach according to which the LSB of video frame pixels are replaced by LSB of image pixels. The RGB pixel values are in binary form (8-bit) and the last three bits are to be replaced. I am not getting any insight into how to proceed. Also, I need to use a method by which I can decrypt the video once encrypted.
Python code that deals with video
import numpy as np
import cv2 as cv
from numpy import binary_repr
from PIL import Image
vidcap = cv.VideoCapture("video.mp4")
if not vidcap.isOpened():
print("Cannot open")
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)
# Display the resulting frame
cv.imshow('frame', gray)
width, height, d= frame.shape
print("reshaped...")
row=int(width*height)
newframe = frame.reshape(row,3) #2D mein change kiya
newframe_list=newframe.tolist()
# print(type(newframe_list))
all_pixels=[] #empty list
# print(newframe_list)
for i in newframe_list:
all_pixels.extend(i)
for i in all_pixels:
x=np.binary_repr(all_pixels[i], width=8)
vidpix=x[5:]
print(x)
print("image pixels")
#kiwi wali image ke pixels iterate kr rhe
def img_pix():
img = Image.open("kiwi.jpg")
pixels = img.load() # this is not a list, nor is it list()'able
w, h = img.size
all_img_pixels = []
for m in range(w):
for n in range(h):
cpixel = pixels[m, n]
all_img_pixels.append(cpixel)
for m in range(w):
for n in range(3):
z = np.binary_repr(all_img_pixels[m][n], width=8)
imgpix = z[6:]
print(z)
img_pix()
if cv.waitKey(1) == ord('q'):
break
# When everything done, release the capture
vidcap.release()
cv.destroyAllWindows()
code dealing with image
import numpy as np
import cv2 as cv
from PIL import Image
from numpy import binary_repr
def img_pix():
img = Image.open("kiwi.jpg")
pixels = img.load() # this is not a list, nor is it list()'able
width, height = img.size
all_img_pixels = []
for m in range(width):
for n in range(height):
cpixel = pixels[m, n]
all_img_pixels.append(cpixel)
for m in range(width):
for n in range(3):
z=np.binary_repr(all_img_pixels[m][n], width=8)
imgpix=z[5:]
print(imgpix)
img_pix()