Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python numpy + opencv + overlay image

import cv2

background = cv2.imread('field.jpg')
overlay = cv2.imread('dice.png')

added_image = cv2.addWeighted(background,0.4,overlay,0.1,0)

cv2.imwrite('combined.png', added_image)
Comment

python numpy + opencv + overlay image

import cv2
import numpy as np

def overlay_transparent(background, overlay, x, y):

    background_width = background.shape[1]
    background_height = background.shape[0]

    if x >= background_width or y >= background_height:
        return background

    h, w = overlay.shape[0], overlay.shape[1]

    if x + w > background_width:
        w = background_width - x
        overlay = overlay[:, :w]

    if y + h > background_height:
        h = background_height - y
        overlay = overlay[:h]

    if overlay.shape[2] < 4:
        overlay = np.concatenate(
            [
                overlay,
                np.ones((overlay.shape[0], overlay.shape[1], 1), dtype = overlay.dtype) * 255
            ],
            axis = 2,
        )

    overlay_image = overlay[..., :3]
    mask = overlay[..., 3:] / 255.0

    background[y:y+h, x:x+w] = (1.0 - mask) * background[y:y+h, x:x+w] + mask * overlay_image

    return background
Comment

PREVIOUS NEXT
Code Example
Python :: !python read data from mysql and export to xecel 
Python :: cache in django 
Python :: how to make a number guessing game in python 
Python :: adding bootstrap grid dynamically django 
Python :: columnspan vs column tkinter 
Python :: scrapy link extractors in regular spiders 
Python :: Blender Python set center to center of mass 
Python :: carnage 
Python :: django user refistration 
Python :: Now, we will first look at the simplest way to scan ports with Python 
Python :: fcpython.com 
Python :: increment numper in python 
Python :: ensure string length 2 python 
Python :: xkcd remove feature matplotlib 
Python :: python to java converter 
Python :: numpy compute min over all axes except 
Python :: http online json 
Python :: How to estimate memory of dataset using python command 
Python :: select values for row matching condition 
Python :: go to python 
Python :: picture as background of seaborn plot python 
Python :: python get pc runtime 
Python :: Return a sorted copy of the list. Does not modify original list. 
Python :: Tableau prep encoding to a set of fields in a flow 
Python :: python modules screen 
Python :: prime number program in python using function 
Python :: Python - Comment vérifier une corde contient un nombre 
Python :: Constructing a Class with __init__ function 
Python :: sample one point from distribution python 
Python :: var person 
ADD CONTENT
Topic
Content
Source link
Name
5+9 =