0

I have a logo and I am trying to put this logo into my video. When I add the logo with below codes, logo couldnt be original color, it shows transparent. But I dont want to transparency I need to put original color format.

I get this output:

enter image description here

This is my code:

img_path = 'ap_logo.png'
logo = cv2.imread(img_path,cv2.IMREAD_UNCHANGED)
#
#
watermark = image_resize(logo, height=300)
watermark = cv2.cvtColor(watermark, cv2.COLOR_BGR2BGRA)
watermark_h, watermark_w, watermark_c = watermark.shape
ret, frame = cap.read()
frame = cv2.flip(frame, 1)
frame = cv2.rotate(frame, cv2.ROTATE_90_CLOCKWISE)

frame_h, frame_w, frame_c = frame.shape
# # overlay with 4 channel BGR and Alpha
overlay = np.zeros((frame_h, frame_w, 4), dtype='uint8')

for i in range(0, watermark_h):
    print(i)
    for j in range(0, watermark_w):
        if watermark[i, j][3] != 0:
            h_offset = frame_h - watermark_h
            w_offset = frame_w - watermark_w
            overlay[h_offset + i, w_offset + j] = watermark[i, j]



while(True):
    ret, frame = cap.read()
    frame = cv2.flip(frame, 1)
    frame = cv2.rotate(frame, cv2.ROTATE_90_CLOCKWISE)
    frame = cv2.cvtColor(frame, cv2.COLOR_BGR2BGRA)

    cv2.addWeighted(overlay, 0.25, frame, 1.0, 0, frame)

    # Display the resulting frame
    frame = cv2.cvtColor(frame, cv2.COLOR_BGRA2BGR)

    if ret:
        cv2.imshow('Frame', frame)
        out.write(frame)  # file a ilgili frame yazılıyor
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break


#When everything done, relase the capture
cap.release()
out.release() # saved
cv2.destroyAllWindows()
Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
CKocar
  • 566
  • 9
  • 25
  • Does this answer your question? [Using openCV to overlay transparent image onto another image](https://stackoverflow.com/questions/40895785/using-opencv-to-overlay-transparent-image-onto-another-image) – Christoph Rackwitz Dec 05 '22 at 14:15
  • @ChristophRackwitz no, because I need frame parameter to save file, this topic only use cv2.imwrite command – CKocar Dec 05 '22 at 14:30
  • ok so don't use imwrite? understand the code you are shown. you asked about composing a transparent image over another image. that is precisely the answer. if you refuse to see, I won't force you. -- do take the [tour] (complete it) and review [ask] and [mre] – Christoph Rackwitz Dec 05 '22 at 14:39
  • No, I don't want it to be transparent. This code is making it transparent. I want to put the picture on the video in the original way – CKocar Dec 05 '22 at 14:42
  • You can't do it with "cv2.addWeighted". do it like this. https://stackoverflow.com/questions/14063070/overlay-a-smaller-image-on-a-larger-image-python-opencv – Ari Dec 05 '22 at 14:58
  • Make a mask for just the logo symbol. Then use the mask to merge the logo image and the background image using np.where(). – fmw42 Dec 06 '22 at 00:51

0 Answers0