向skimage中的图像帧添加高斯噪声

时间:2019-02-24 13:57:45

标签: python opencv video-processing object-detection scikit-image

我一直在尝试向视频帧中添加高斯噪声,但出现此错误,并且我不知道如何处理。

回溯(最近通话最近):   在第119行的文件“ yolo_video.py”     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_函数'cv :: dnn :: dnn4_v20180917 :: blobFromImages'中的.depth()

这是我的代码:

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

帮帮我。 您的回答对我真的很有帮助。

0 个答案:

没有答案