import numpy as np
import cv2
import matplotlib.pyplot as plt
img1 = cv2.imread(r'C:UsersAdministratorDesktopd0239b1005e063e5e7028963bfb8d1f.png',1)
# img2 = cv2.imread(r'C:UsersAdministratorDesktop20231121134301.png',1)
img2 = cv2.imread(r'C:UsersAdministratorDesktop600d7fe.png',1)
img2=img2[120:240,240:380]
h, w, c = img2.shape
roi = img1[0:h, 0:w]
img2gray = cv2.cvtColor(img2,cv2.COLOR_BGR2GRAY)
ret, mask = cv2.threshold(img2gray, 10, 255, cv2.THRESH_BINARY)
mask_inv = cv2.bitwise_not(mask)
img1_bg = cv2.bitwise_and(roi,img2,mask = mask_inv)
img2_fg = cv2.bitwise_and(roi,img2,mask = mask)
dst = cv2.add(img2_fg, img1_bg)
img1[0:h, 0:w ] = dst
# test1=cv2.bitwise_or(dst1,dst2,mask=None)
cv2.imshow('1',img1)
cv2.waitKey(0)
cv2.destroyAllWindows()
原图
bitwise_and进行叠加,mask进行替换
# import numpy as np
# import cv2
# '''图像水印'''
# import matplotlib.pyplot as plt
# img1 = cv2.imread(r'C:UsersAdministratorDesktopd0239b1005e063e5e7028963bfb8d1f.png',1)
# # img2 = cv2.imread(r'C:UsersAdministratorDesktop20231121134301.png',1)
# img2 = cv2.imread(r'C:UsersAdministratorDesktop600d7fe.png',1)
# img2=img2[120:240,240:380]
# # h, w, c = img2.shape
# # roi = img1[0:h, 0:w]
# img2gray = cv2.cvtColor(img2,cv2.COLOR_BGR2GRAY)
# ret, mask = cv2.threshold(img2gray, 10, 255, cv2.THRESH_BINARY)
# # mask_inv = cv2.bitwise_not(mask)
# # img1_bg = cv2.bitwise_and(roi,img2,mask = mask_inv)
# # img2_fg = cv2.bitwise_and(roi,img2,mask = mask)
# # dst = cv2.add(img2_fg, img1_bg)
# # img1[0:h, 0:w ] = dst
# # txt="Lionel Messi"
# # font = cv2.FONT_HERSHEY_SIMPLEX
# # cv2.putText(img1,txt,(50,500), font, 2,(255,255,255),2,cv2.LINE_AA)
# # cv2.imshow('111',img1)
# # cv2.waitKey(0)
# # cv2.destroyAllWindows()
# # cv2.imwrite('./test.png',img1)
#
#
#
# # 图像副本灰度图轮廓识别
# img = cv2.imread('test.png',1)
# cv2.imshow('Original',img)
# gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# template=img2gray
# cv2.imshow('Template',template)
# w,h = template.shape[0], template.shape[1]
# matched = cv2.matchTemplate(gray,template,cv2.TM_CCOEFF_NORMED)
# threshold = 0.5
# loc = np.where( matched >= threshold)
# for pt in zip(*loc[::-1]):
# cv2.rectangle(img, pt, (pt[0] + w, pt[1] + h), (0,255,255), 2)
# cv2.imshow('Matched with Template',img)
# cv2.waitKey(0)
# cv2.destroyAllWindows()
# video 播放
import cv2
from ffpyplayer.player import MediaPlayer
file=r"C:UsersAdministratorDesktopcoverr-road-in-vermont-8779-1080p.mp4"
file1=r'D:xy_fs_trysilverArkvideo_and_picopencv_trainvideo.mp4'
video=cv2.VideoCapture(file1)
player = MediaPlayer(file1)
while True:
ret, frame=video.read()
audio_frame, val = player.get_frame()
if not ret:
print("End of video")
break
if cv2.waitKey(1) == ord("q"):
break
cv2.imshow("Video", frame)
if val != 'eof' and audio_frame is not None:
#audio
img, t = audio_frame
video.release()
cv2.destroyAllWindows()
# import cv2
# import os
# #OpenCV Python - 从视频中提取图像
# file=r"C:UsersAdministratorDesktopcoverr-road-in-vermont-8779-1080p.mp4"
# file1=r'D:xy_fs_trysilverArkvideo_and_picopencv_trainvideo.mp4'
# cam = cv2.VideoCapture(file1)
#
# frameno = 0
# while(True):
# ret,frame = cam.read()
# if ret:
# # if video is still left continue creating images
# name = './image/'+ str(frameno) + '.jpg'
# print ('new frame captured...' + name)
#
# cv2.imwrite(name, frame)
# frameno += 1
# else:
# break
#
# cam.release()
# cv2.destroyAllWindows()
# #读取图片成视频
# import cv2
# import numpy as np
# import glob
#
# img_array = []
# for filename in glob.glob('./image/*.jpg'):
# img = cv2.imread(filename)
# height, width, layers = img.shape
# size = (width,height)
# img_array.append(img)
#
# out = cv2.VideoWriter('video.mp4',cv2.VideoWriter_fourcc(*'DIVX'), 15, size)
#
# for i in range(len(img_array)):
# out.write(img_array[i])
# out.release()
原文地址:https://blog.csdn.net/Steven_yang_1/article/details/134531670
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.7code.cn/show_8769.html
如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除!
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。