python - 向 skimage 中的图像帧添加高斯噪声
问题描述
我一直在尝试向视频帧添加高斯噪声,但我收到了这个错误,我不知道如何处理它。
回溯(最近一次调用):文件“yolo_video.py”,第 119 行,swapRB=True,crop=False) cv2.error: OpenCV(4.0.0) C:\projects\opencv-python\opencv\modules\ dnn\src\dnn.cpp:189: 错误: (-215: 断言失败) image.depth() == blob_.depth() in function 'cv::dnn::dnn4_v20180917::blobFromImages'
这是我的代码:
noise_factor=0.05
count=0
from skimage import util
while True:
count+=1
(grabbed, frame) = vs.read()
frame_noisy = frame.copy() + noise_factor * np.random.normal(loc=0.0, scale=1.0, size=frame.shape)
if not grabbed:
break
if W is None or H is None:
(H, W) = frame.shape[:2]
blob = cv2.dnn.blobFromImage(frame_noisy, 1 /250, (416, 416),
swapRB=True, crop=False)
net.setInput(blob)
start = time.time()
layerOutputs = net.forward(ln)
end = time.time()
boxes = []
confidences = []
classIDs = []
for output in layerOutputs:
# loop over each of the detections
for detection in output:
scores = detection[5:]
classID = np.argmax(scores)
confidence = scores[classID]
if confidence > args["confidence"]:
box = detection[0:4] * np.array([W, H, W, H])
(centerX, centerY, width, height) = box.astype("int")
x = int(centerX - (width / 2))
y = int(centerY - (height / 2))
boxes.append([x, y, int(width), int(height)])
confidences.append(float(confidence))
classIDs.append(classID)
idxs = cv2.dnn.NMSBoxes(boxes, confidences, args["confidence"],
args["threshold"])
if len(idxs) > 0:
for i in idxs.flatten():
(x, y) = (boxes[i][0], boxes[i][1])
(w, h) = (boxes[i][2], boxes[i][3])
color = [int(c) for c in COLORS[classIDs[i]]]
cv2.rectangle(frame_noisy, (x, y), (x + w, y + h), color, 2)
text = "{}: {:.4f}".format(LABELS[classIDs[i]],
confidences[i])
cv2.putText(frame_noisy, text, (x, y - 5),
cv2.FONT_HERSHEY_SIMPLEX, 0.5, color, 2)
if writer is None:
fourcc = cv2.VideoWriter_fourcc(*"MJPG")
writer = cv2.VideoWriter(args["output"], fourcc, 30,
(frame.shape[1], frame.shape[0]), True)
if total > 0:
elap = (end - start)
print("[INFO] single frame took {:.4f} seconds".format(elap))
print("[INFO] estimated total time to finish: {:.4f}".format(
elap * total))
if(count==70):
import matplotlib.pyplot as plt
plt.imshow(frame_noisy)
plt.show()
writer.write(frame_noisy)
enter code here
帮帮我,伙计们。你的回答对我真的很有帮助。
解决方案
推荐阅读
- matlab - 如何训练具有多个时间序列的神经网络?
- python - 如何修复谷歌子模块导入错误?
- r - R 代码按 % 拆分值,然后为每个新的 % 值分配一个新类别
- android-studio - 如何使用 exo 播放器在视图寻呼机中播放一个视频
- ruby - mysql2 gem 坚持使用 openssl 1.0 而不是 1.1
- javascript - 在函数中反应 useEffect
- amazon-web-services - AWS MQ 维护时段
- oracle - Oracle SP:PLS-00103:在预期以下情况之一时遇到符号“`”:
- php - 显示精选图片向左浮动以获取 Wordpress 后的摘录
- python - np.random.poisson 是否适用于非常小的数字?