Добавление гауссовского шума к кадрам изображения в образе лыжи - PullRequest
0 голосов
/ 24 февраля 2019

Я пытался добавить гауссовский шум к видеокадрам, но я получил эту ошибку, и я не знаю, как с ней справиться.

Traceback (последний вызов был последним): Файл "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 () в функции '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

Помогите, ребята.Ваши ответы будут очень полезны для меня.

...