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

"Argument 'alpha' can not be treated as a double" #35

Closed
thekryz opened this issue Jul 15, 2020 · 8 comments · Fixed by #49
Closed

"Argument 'alpha' can not be treated as a double" #35

thekryz opened this issue Jul 15, 2020 · 8 comments · Fixed by #49

Comments

@thekryz
Copy link

thekryz commented Jul 15, 2020

When I try to run python videopose.py with the demo video, I get the message "Argument 'alpha' can not be treated as a double:

(base) xxx@yyy:~/miniconda3/lib/python3.7/site-packages/video-to-pose3D$ python videopose.py 
the video is 25.051 f/s
Loading YOLO model..
/opt/conda/conda-bld/pytorch_1591914880026/work/torch/csrc/utils/python_arg_parser.cpp:756: UserWarning: This overload of nonzero is deprecated:
	nonzero(Tensor input, *, Tensor out)
Consider using one of the following signatures instead:
	nonzero(Tensor input, *, bool as_tuple)
Loading pose model from joints_detectors/Alphapose/models/sppe/duc_se.pth
Start pose estimation...
  0%|▎                                                                                                    | 1/338 [00:00<00:46,  7.18it/s]Exception in thread Thread-4:
Traceback (most recent call last):
  File "/home/xxx/miniconda3/lib/python3.7/threading.py", line 926, in _bootstrap_inner
    self.run()
  File "/home/xxx/miniconda3/lib/python3.7/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/home/xxx/miniconda3/lib/python3.7/site-packages/video-to-pose3D/joints_detectors/Alphapose/dataloader.py", line 678, in update
    img = vis_frame(orig_img, result)
  File "/home/xxx/miniconda3/lib/python3.7/site-packages/video-to-pose3D/joints_detectors/Alphapose/fn.py", line 198, in vis_frame
    img = cv2.addWeighted(bg, transparency, img, 1 - transparency, 0)
TypeError: Argument 'alpha' can not be treated as a double

The script seems to continue, though I'm not sure if it eventually finishes, since I had to interrupt.

@MikeXuQ
Copy link

MikeXuQ commented Jul 16, 2020

Hi, I have met the same question. Have you solved it?

@smq20181217
Copy link

I have met the same problem, when i try to reduce the version of opencv-python to 3 and reinstall ffmpeg, this probem did not recur

@zh-plus
Copy link
Owner

zh-plus commented Jul 28, 2020

The "alpha" argument is the second argument in

img = cv2.addWeighted(bg, transparency, img, 1 - transparency, 0)

Since I cannot reproduce this issue, you can set a breakpoint there and see if the value of transparency cannot be converted to double. From my point of view, replacing transparency by float(transparency) may help.

Also, it may be caused by the incompatibility of opencv-python package. In my environment, the version is 4.1.0.25, which may help addressing this issue.

@zh-plus zh-plus closed this as completed Aug 17, 2020
@sysu17363044
Copy link

have you solved the problem yet? plz help

@wordball
Copy link

Might be a bit late but did you make sure that alpha was the correct data type? For example, if alpha was supposed to be an integer, did you use the int() method or ensure that the value that would replace alpha is an integer?

@wangzexi
Copy link
Contributor

wangzexi commented Jun 30, 2021

Same problem.
I found the type of transparency is a torch.Tensor, so using torch.tensor(3.14).item() to get real value.

transparency = max(0, min(1, kp_scores[n])).item()
# ...
transparency = max(0, min(1, 0.5 * (kp_scores[start_p] + kp_scores[end_p]))).item()

@wangzexi wangzexi mentioned this issue Jun 30, 2021
@zh-plus zh-plus linked a pull request Jul 27, 2021 that will close this issue
@gyg123456
Copy link

I have met the same problem, when i try to reduce the version of opencv-python to 3 and reinstall ffmpeg, this probem did not recur

It works,really thanks

@javadasoodeh
Copy link

javadasoodeh commented Jun 11, 2023

I encountered a similar issue with the function 'AddWeighted'. However, I was able to address the problem by developing a custom function, which works well. The problem arose when I attempted to pass an array as an alpha parameter, resulting in the error 'Argument alpha cannot be treated as a double'. Consequently, I sought to investigate the underlying issue and, as a solution, introduced a new function named 'customAddWeighted'.

To see the full code: https://github.com/javadasoodeh/CV/blob/main/opencv_basic/alpha_blending.py

Please note that the provided link may be subject to change. To access the relevant information, kindly navigate to the 'https://github.com/javadasoodeh/CV' section and search for the file name 'alpha_blending.py'.

def customAddWeighted(src1, alpha, src2, beta, gamma=0):
    # Check if the images have the same size
    if src1.shape != src2.shape:
        raise ValueError("Input images must have the same size.")

    # Perform alpha blending
    blended_image = np.clip(src1 * alpha[:, :, np.newaxis] + src2 * beta[:, :, np.newaxis] + gamma, 0, 255).astype(
        np.uint8)

    return blended_image

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

Successfully merging a pull request may close this issue.

9 participants