- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在 open-cv 中创建自己的面部过滤增强现实程序。这个想法是将海狸映射到用户的脸上。目前,使用“cv2.imread(...)”加载此图像时,我无法获得适当的透明度。它在背景中看起来是黑色的,并且经常在某些白色区域中部分显示。当我在 Photoshop 中打开这张图片时,我完全有能力将这张图片移动到具有预期透明度结果的背景上。我想知道 alpha 是否没有正确渲染。这是我加载图像的相关代码。
import numpy
import cv2
def augment_stream(face: numpy.array, augment: numpy.array) -> numpy.array:
face_h, face_w, _ = face.shape
augment_h, augment_w, _ = augment.shape
scalar = min(face_h / augment_h, face_w / augment_w)
delta_augment_h = int(scalar * augment_h)
delta_augment_w = int(scalar * augment_w)
delta_augment_shape = (delta_augment_w, delta_augment_h)
resized_augment = cv2.resize(augment, delta_augment_shape)
augmented_face = face.copy()
dark_pixels = (resized_augment < 250).all(axis=2)
offset_x = int((face_w - delta_augment_w) / 2)
offset_y = int((face_h - delta_augment_h) / 2)
augmented_face[offset_y: offset_y+delta_augment_h, offset_x: offset_x+delta_augment_w][dark_pixels] = resized_augment[dark_pixels]
return augmented_face
def main():
stream = cv2.VideoCapture(0)
cascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")
augment = cv2.imread('assets/normal.png')
# tmp = cv2.cvtColor(augment, cv2.COLOR_BGR2GRAY)
# _,alpha = cv2.threshold(tmp,0,255,cv2.THRESH_BINARY)
# b, g, r = cv2.split(augment)
# rgba = [b,g,r, alpha]
# dst = cv2.merge(rgba,4)
# cv2.imwrite("assets/normal.png", dst)
while True:
ret, border = stream.read()
border_h, border_w, _ = border.shape
bw = cv2.equalizeHist(cv2.cvtColor(border, cv2.COLOR_BGR2GRAY))
rects = cascade.detectMultiScale(bw, scaleFactor=1.3, minNeighbors=4, minSize=(30, 30), flags=cv2.CASCADE_SCALE_IMAGE)
for x, y, w, h in rects:
y0 = int(y - 0.25*h)
y1 = int(y + 0.75*h)
x0 = x
x1 = x + w
if x0 < 0 or x1 > border_w or y0 < 0 or y1 > border_h:
continue
border[y0: y1, x0: x1] = augment_stream(border[y0: y1, x0: x1], augment)
cv2.imshow('border', border)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
stream.release()
cv2.destroyAllWindows()
if __name__ == '__main__':
main()
最佳答案
使用问题 overlay a smaller image on a larger image python OpenCv 中的示例
我将其缩小为仅显示如何放置图像
cv2.IMREAD_UNCHANGED
将其加载为 RGBA
. RGB
和 A
A
为 image
创建掩码和 border
import cv2
stream = cv2.VideoCapture(0)
# load RGBA
augment = cv2.imread('image.png', cv2.IMREAD_UNCHANGED) # load RGBA
# make it smaller then frame - only for test
W = 320
H = 240
augment = cv2.resize(augment, (W, H))
# split image and alpha
image = augment[:,:,0:3]
alpha = augment[:,:,3]
mask_image = alpha / 255.0
mask_border = 1.0 - mask_image
# ROI - region of interest
x1 = 200
y1 = 100
x2 = x1 + W
y2 = y1 + H
while True:
ret, border = stream.read()
# copy only in some region (ROI) (don't assign to variable) but gives worse result
#cv2.copyTo(image, alpha, border[y1:y2, x1:x2])
for c in range(0, 3): # channels RGB
border[y1:y2, x1:x2, c] = (image[:, :, c]*mask_image + border[y1:y2, x1:x2, c]*mask_border)
cv2.imshow('border', border)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
stream.release()
cv2.destroyAllWindows()
cv2.copyTo(image, mask_image, border)
但它给出了更糟糕的结果——也许掩码/alpha 需要 3 个 channel 。
关于python - OpenCV:增强视频流源 .png 未按预期呈现透明度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60290354/
我正在用 symfony2 编写应用程序,但我遇到了视频流问题。 如果一个 Action 需要很长时间才能执行 - 例如 1 分钟,整个应用程序将被卡住(当在第二个选项卡中打开时)并且必须等待该执行结
我正在用 symfony2 编写应用程序,但我遇到了视频流问题。 如果一个 Action 需要很长时间才能执行 - 例如 1 分钟,整个应用程序将被卡住(当在第二个选项卡中打开时)并且必须等待该执行结
我正在尝试用视频流做一个应用程序,现在我只能从服务器向客户端发送一张图像。当我尝试在客户端发送不止一张图像时,我收到以下错误:“参数无效。”在 pictureBox1.Image = new Bitm
我正在使用 mediaViews 和 html5 在我们的 cakephp 网站上流式传输视频截屏。我正在为播放器使用 videojs,但遇到了一些问题: 不会在 safari/ipad/iphone
我已经安装了fluent-ffmpeg和ffmpeg-static以将流转换为HTML可复制的视频。如何使用这些软件包在客户端中显示流? 服务器端( main.js ): const { app, B
我在我的应用程序中实现了 TTS(文本转语音)功能。一切都很顺利,但现在我遇到了一个无法找到解决方案的问题。 基本上,我在激活 TTS 功能之前获得音频焦点。在实际的应用程序中,当我这样做时音乐就会停
我已经执行了开源社区链接发布的 AudioPlayer.java 示例 Audio Player Tutorial 我得到以下异常 Exception in thread "main" java.la
有什么方法可以在iOS原生App中通过URL播放无法下载或保存到本地的视频流。我想让用户观看视频,但他不能在本地下载或保存视频(通过第 3 方下载器应用程序)。 在 MPMoviePlayerCont
我正在开发用于网络吞吐量测试的点对点视频流。两个对等点之间的网络支持低比特率传输。 我使用 OpenCV 为视频流制作了简单的 python 程序。 该程序从网络摄像头抓取视频帧并将其编码为 JPEG
我正在我的应用程序中流式传输实时视频。我有一个 .m3u8 链接,它在 vlc 播放器中完美运行。但是当我在我的应用程序中播放这个流时,视频的可视化被破坏了(见截图)。有谁知道,这可能是什么原因造成的
好的。因此,有数十亿种不同的 Android 设备。我有一个视频流服务,非常适用于 iOS。我的应用程序具有实时视频功能和保存的视频剪辑播放功能(也可以流式传输到设备)。我在不同的 Android 设
我有一个屏幕共享应用程序 (WebRTC)。一个用户想与另一个用户共享他的屏幕。就像一个应用程序在用户 1 机器上运行而另一个应用程序在用户 2 机器上运行。用户 1 想要共享他的屏幕,现在如何在用户
我正在尝试提供即时转码的视频。不幸的是,这意味着寻求不起作用。我假设这是因为浏览器不知道视频有多长,因此无法正确显示搜索栏。 有谁知道是否可以对视频的时长进行硬编码? 我想到的另一个选择可能是创建我自
在将解复用的 h264 解码输出发送到 gstreamer 管道中的 autovideosink 之前,是否可以在两者之间提供一些延迟。如果是这样,任何人都可以发布示例管道来做到这一点。 我使用的管道
一直在把我的头发拉出来,这本来应该是一项快速而简单的任务。 我有一个自托管的 WCF 服务,我需要在其中实现实时视频转码,转码本身不是问题,使用 FFMpeg 到本地临时文件。 我的代码的快速示例;
我想在 C# 应用程序和浏览器之间建立视频流。 我使用 Websockets 进行通信。 视频源是网络摄像头。 我可以请求单个 PNG 帧,但速度太慢了。 websocket 服务器( Ratchet
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 9 年前。 Improve
是否可以在 lync 2010 或 2013 中捕获 lync session 的视频流?我已经在我们的实验室中运行了测试版。 UCMA 为 AudioVideoFlow 提供了钩子(Hook),但似
我有一个 ffmpeg 命令,它接收帧流并输出 ogg 视频。如何从另一个文件中添加音频? ffmpeg -f rawvideo -pix_fmt bgr24 -s WIDTHxHEIGHT -r 3
我正在使用全息镜头,并且我正在尝试保存具有可用世界/投影矩阵的视频流。我一直在尝试拍摄一系列照片并保存数据,但我找不到保存图像和矩阵的方法。 保存到磁盘时,没有获取照片捕获帧(包含矩阵数据)的选项,保
我是一名优秀的程序员,十分优秀!