Пример #1
0
def add_colormap2img(img, atten_norm):
    heat_map = cv2.applycolormap(atten_norm.astype(np.uint8), cv2.colormap_jet)
    img = cv2.addweighted(img.astype(np.uint8), 0.5, heat_map.astype(np.uint8),
                          0.5, 0)
    return img
Пример #2
0
    if not ret:
        break
    count += 1
    img = np.flip(img, axis=1)

hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)

lower_black = np.array([0, 120, 50])
upper_black = np.array([10, 255, 255])
mask1 = cv2.inRange(hsv, lower_red, upper_red)

lower_black = np.array([170, 120, 70])
upper_black = np.array([180, 255, 255])
mask2 = cv2.inRange(hsv, lower_red, upper_red)

mask1 = mask1 + mask2

mask1 = cv2.morphologyEx(mask1, cv2.MORPH_OPEN, np.ones((3, 3), np.uint8))
mask1 = cv2.morphologyEx(mask1, cv2.MORPH_DILATE, np.ones((3, 3), np.uint8))
mask2 = cv2.bitwise_not(mask1)
res1 = cv2.bitwise_and(img, img, mask=mask2)
res2 = cv2.bitwise_and(background, background, mask=mask1)

finaloutput = cv2.addweighted(res1, 1, res2, 1, 0)
out.write(finaloutput)
cv2.imshow('magic', finaloutput)
cv2.waitKey(1)

cap.release()
out.release()
cv2.destroyAllWindows()