Esempio n. 1
0
                if len(approx) >= 4:
                    x, y, w, h = cv2.boundingRect(approx)
                    x2 = x + w
                    y2 = y + h
                    for d in dice:
                        if (d.isBelongs([x, x2], [y, y2])):
                            if d.dots < 7:
                                d.dots += 1
                            cv2.drawContours(frame, [approx], 0, (0, 200, 200),
                                             2)
                            cv2.drawContours(maskDots, [approx], 0,
                                             (90, 90, 90), 2)

            for d in dice:
                if d.dots == 0:
                    d.dots = 0
                else:
                    d.dots -= 1
            #endregion

            if len(dice) > 0:
                if hue["color"] == "red":
                    values[0] = dice[0].dots
                elif hue["color"] == "green":
                    values[1] = dice[0].dots
                elif hue["color"] == "blue":
                    values[2] = dice[0].dots

        data = str(values)[1:-1]
        server.send(data)
Esempio n. 2
0
        if len(approx) >= 4:
            x, y, w, h = cv2.boundingRect(approx)
            x2 = x + w
            y2 = y + h
            for d in dice:
                if (d.isBelongs([x, x2], [y, y2])):
                    d.dots += 1
                    cv2.drawContours(frame, [approx], 0, (0, 200, 200), 2)
                    cv2.drawContours(maskDots, [approx], 0, (90, 90, 90), 2)

    if len(dice) < 3:
        for i in range(len(dice), 3):
            dice.append(Die())
    for d in dice:
        if d.dots == 0:
            d.dots = 0
        else:
            d.dots = d.dots - 1

    data = ', '.join([d.color + ": " + str(d.dots) for d in dice])
    server.send(data)
    #endregion

    dicePoints = ', '.join([str(d.dots) for d in dice])
    cv2.putText(frame, dicePoints, (50, 100), cv2.FONT_HERSHEY_COMPLEX, 2,
                (255, 255, 255), 3)
    currentFrame += 1

    # Draw the frames
    cv2.namedWindow("Analysed", 0)
    cv2.resizeWindow("Analysed", 640, 360)