Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

addWeighted outputs incorrectly when any element in src2 is zero #1018

Open
3 of 4 tasks
willSapgreen opened this issue Aug 12, 2024 · 1 comment
Open
3 of 4 tasks

Comments

@willSapgreen
Copy link

Expected behaviour

For each pixel, the output should follow
dst = src1 * alpha + src2 * beta + gamma

Actual behaviour

If a pixel's value in src2 is zero,
dst = src1

For example, given alpha = 0.5
src1 [110 126 239]
src2 [0 0 0]
dst [110 126 239]

Steps to reproduce

  • example code
alpha = 0.5
beta = 1.0 - alpha
dst = cv2.addWeighted(src1, alpha, src2, beta, 0.0)
  • operating system:
    Ubuntu 20.04.6 LTS

  • architecture:
    x86

  • opencv-python version:
    4.10.0

Issue submission checklist
  • This is not a generic OpenCV usage question (looking for help for coding, other usage questions, homework etc.)
  • I have read the README of this repository and understand that this repository provides only an automated build toolchain for OpenCV Python packages (there is no actual OpenCV code here)
  • The issue is related to the build scripts in this repository, to the pre-built binaries or is a feature request (such as "please enable this additional dependency")
  • I'm using the latest version of opencv-python
@asmorkalov
Copy link
Collaborator

Just tried current 4.x branch. It works well:

import cv2
import numpy as np

src1 = np.array([110, 126, 239], dtype=np.uint8)
src2 = np.array([0, 0, 0], dtype=np.uint8)

alpha = 0.5
beta = 1.0 - alpha
dst = cv2.addWeighted(src1, alpha, src2, beta, 0.0)
print(dst)

Output:

[[ 55]
 [ 63]
 [120]]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants