错误:When the input arrays in add/subtract/multiply/divide functions have different types, ...

OpenCV杂记 - Mat in C++ 1 概述 Mat类是OpenCV表达二维图片的基础。 经过简单阅读有关Mat的documentation,记录其中提出的几个关键要点。 OpenCV 的API函数,对图像的输出参数都会自动管理内存,调用者可不必亲自管理。但是如果调用者已经对输出参数配置好了合适大小的内纯,API会自动福永该内存而不是重新申请。 在使用OpenCV提供的API时,大部分时间不需要考虑内存管理。 Mat... 阅读详情
AI摘要

在使用OpenCV的加权和函数时遇到了错误,原因是输入图像的数据类型不一致。解决方法包括在操作前将图像转换为相同的格式,如astype(np.uint8),或者在调用函数时指定dtype参数进行类型转换。通过这两种方式,可以避免'arithm_op'函数中因输入数组类型不同引发的错误。

"When the input arrays in add/subtract/multiply/divide functions have different "

报错:"When the input arrays in add/subtract/multiply/divide functions have different types, the output array type must be explicitly specified in function 'arithm_op'" 

在写热力图绘制函数时,遇到以下错误:

Traceback (most recent call last):
  File "/media/wzg/Disk3T/ano_voting_cascade/inference_heatmap.py", line 177, in <module>
    heatmap_img = Vis_obj.intensity_heatmap(background_img=frame,intensity_map=intensity_map,blue_mask_weight=0.3,heat_map_weight=0.5)
  File "/media/wzg/Disk3T/ano_voting_cascade/src/tools/Class_Visualization.py", line 444, in intensity_heatmap
    heatmap_base = cv2.addWeighted(blue_mask, blue_mask_weight, background_img_norm, 1 - blue_mask_weight, 0).astype(np.uint8)
cv2.error: OpenCV(4.2.0) /io/opencv/modules/core/src/arithm.cpp:693: error: (-5:Bad argument) When the input arrays in add/subtract/multiply/divide functions have different types, the output array type must be explicitly specified in function 'arithm_op'

原因:错误的主要原因是 cv2.addWeighted(img,0.01,img0,0.99,0, CV_32F) 的两幅图像的格式不一致。

修改方法1:强制把两幅图的格式转为相同的数据格式就行了,我用的是“.astype(np.uint8)”,如下

blue_mask = cv2.rectangle(background_img.copy(), (0, 0), background_img.shape[0:2], (0, 0, 255), -1).astype(np.uint8)
heatmap_base = cv2.addWeighted(blue_mask, blue_mask_weight, background_img_norm, 1 - blue_mask_weight, 0).astype(np.uint8)

修改方法2:在加权和时强迫格式转换

img2 = cv2.addWeighted(img,0.01,img0,0.99,0, dtype = cv2.CV_32F)

参考:https://blog.youkuaiyun.com/qq_35250841/article/details/108320967

ansys命令流力磁耦合仿真 文章目录前言一、力磁耦合仿真流程二、静力学仿真三、力磁耦合模型构建四、静磁学仿真总结 前言 一、力磁耦合仿真流程 力磁耦合有限元仿真流程中,首先进行静力学仿真,经过前处理模块、分析计算模块和后处理模块提取三维模型单元应力,然后根据力磁耦合方程中,通过matlab将单元应力导入到磁导率与应力的关系式中,得到单元的相对磁导率。最后采用载荷传递耦合方式,进行静磁学模拟仿真,分析计算得到该载荷下试件的磁场分布。,如下图所示为力磁耦合仿真流程图: 二、静力学仿真 下图为中心预制条形缺陷的Q235钢板试.. 阅读详情

相关推荐

Python+QMT量化交易实战:从零搭建你的第一个极速策略(附完整代码)

本文提供了一份详细的Python+QMT量化交易实战指南,手把手教你从零搭建一个可回测、可实盘的极速策略。内容涵盖环境配置、QMT核心机制解析、双均线策略的完整代码实现、回测优化方法以及实盘部署要点,帮助量化交易新手快速入门并掌握核心开发流程。

b9c0d的博客 1014

error: (-5) When the input arrays in add/subtract/multiply/divide functions have different types

error: (-5) When the input arrays in add/subtract/multiply/divide functions have different types, the output array type must be explicitly specified in function arithm_op 利用OpenCV函数 void addWeighted(I...

共觞的博客 7726

通义灵码+高德 MCP:40分钟开发出游攻略网站

本文介绍了通义灵码与高德MCP在40分钟内快速开发出游攻略网站的全流程。主要内容包括:1)LingmaIDE开发环境的使用方法,涵盖界面操作、代码编辑、调试和智能编码功能;2)通义灵码智能体与高德MCP2.0的集成步骤,通过输入旅行需求即可自动生成包含天气卡片、景点路线等元素的HTML页面;3)重点展示了如何将行程规划导入高德地图APP,实现导航、打车等出行功能。整个开发过程充分利用了通义灵码的智能编码能力和高德地图的服务接口,显著提升了旅游类应用的开发效率。

soso1968的博客 986

When the input arrays in add/subtract/multiply/divide functions have different types, the output arr

python 中使用cv2出现的错误。 背景:自己谢了一个热力图可视化的轮子,代码如下: def intensity_heatmap(background_img, intensity_map, blue_mask_weight=0.3, heat_map_weight=0.5): """ :param background_img: 背景图 shape=[H,W,C] :param intensity_map: 损失强度图 shape=[H,W,C] :para

wzg2016的博客 2179

通达信筹码分布主图源码分享

NOTEXT下区成本:IF(CURRBARSCOUNT<=CONST(XA_26+1),CONST(IF(1,XA_94,XA_94)),DRAWNULL),DOTLINE,COLORYELLOW;NOTEXT上区成本:IF(CURRBARSCOUNT<=CONST(XA_26+1),CONST(IF(1,XA_81,XA_81)),DRAWNULL),DOTLINE,COLORRED;FFG1:DRAWBAND(C线,RGB(255,0,0),XA_33,RGB(255,0,0));

zhibiaogong的博客 3358

[Windows] 发票识别工具。支持xml、pdf、ofd文件。

发票识别是财务自动化中的关键环节,支持多种格式(XML、PDF、OFD)的识别工具能显著提升工作效率。以下介绍基于Windows平台开发此类工具的技术方案。发票识别是财务自动化中的关键环节,支持多种格式(XML、PDF、OFD)的识别工具能显著提升工作效率。以下介绍基于Windows平台开发此类工具的技术方案。

pZC_dqux的博客 668

详解OpenCV的函数cv::add(),并附各种情况的示例代码和运行结果

函数cv::add()用于实现两个Mat类矩阵相加,或者矩阵和标量相加。函数cv::add()的运算公式如下: 从上面的叙述可以看出: 相当于: 虽然可以这样等效操作,但是昊虹君还是建议诸位用标准函数式操作,这样能提高代码的健壮性。函数add()的原型如下: 前四个参数没什么好说的,这里说下最后一个参数dtype,它用于设置输出矩阵的数据类型,具体情况如下: The input arrays and the output array can all have the same or different d

昊虹AI笔记 6229

复旦微FMQL45T900平台RGMII网口调试实战:从PHY寄存器读取异常到链路建立

本文详细记录了复旦微FMQL45T900平台RGMII网口调试的全过程,重点解决了PHY寄存器读取异常问题。通过电压配置调整、时序优化和硬件信号完整性检查,最终成功建立网络链路。文章提供了实用的调试经验和解决方案,适合嵌入式开发人员参考。

weixin_29193359的博客 288

MXNet NumPy 模式(NP on MXNet)速查表实战指南:从数组创建到 GPU 与自动微分

`NP on MXNet` 是 Apache MXNet 为深度学习开发者提供的「NumPy 兼容」编程模式:通过 `mxnet.np` 与 `mxnet.npx` 模块,你可以用接近原生 NumPy 的语法完成张量创建、数学运算、切片索引、文件读写与 GPU 计算,同时无缝衔接 MXNet 的 `autograd` 自动微分与 Gluon 生态。本文以仓库中的 [cheat-sheet.md](

gitblog_00095的博客 493

一桶令牌的时间账本:四类限流算法的边界推演与Guava RateLimiter源码精读

限流的难点不在背出算法名,而在算清每一笔账:按哪一秒计数、超额请求排队还是拒绝、空闲后能否突发、集群总量如何约束。本文在可复现的虚拟时间实验台上对比固定窗口、滑动窗口、漏桶与令牌桶,实测边界双倍突发与分桶滑动的真实上界,拆解Nginx limit_req的千分位记账与延迟机制,纠正Resilience4j常被误称漏桶的说法,并逐行精读Guava SmoothRateLimiter的预消费、懒惰补账与预热积分,复刻迷你限流器与其完成七万次零差异对账,最后给出集群配额、分层防护与参数确定的方法。

曾经“等你生日那天”都遥远得像未来,如今却可欢愉的挥手说“下个十年见” 86万+

【四足机器人项目实战】波士顿spot四足机器人机工程设计及实现分析

主要介绍了波士顿spot机器人的发展历史、四足机器人的硬件系统及电机执行器组成包括硬件系统、关节电机执行器,机载传感器机处理器及电气连接等。概述了四足机器人规划控制、感知、定位及局部地图的相关算法方向。

qq_35635374的博客 4999

cv2.addWeighted 操作 np.array 踩坑记录

cv.addWeighted操作np.array

蓝羽飞鸟的博客 1254

高性能优化的本质

在很早之前,处理器性能的提升一般是通过减小元器件的尺寸,增加元器件的数量,提高主频来实现,这也是摩尔定律所说的,但是由于功耗的影响,主频不能一直增加。后来,由于英伟达的GPU的并行计算的出现,逐渐打破摩尔定律,人们利用多核,SIMD,SIMT来处理大量相同计算的数据,这极大的提高了效率。计算机的算力得到了巨大的提升,但是并行是困难的,对于有数据依赖的程序来说,处理并行是一件及其困难的事,但对于一些简单的数学库的计算,并行的实现相对简单。

发狂的小花的博客 274

difference = cv2.error: OpenCV(4.5.5) :-1: error: (-5:Bad argument) in function ‘subtract‘

报错提示: difference = cv2.subtract(dir_image1 , dir_image2) cv2.error: OpenCV(4.5.5) error: (-5:Bad argument) in function ‘subtract’报错的位置:difference = cv2.subtract(dir_image1 , dir_image2) 主要为传参问题,需要使用: dir_image1 = cv2.imread(dir_image1)读取传入图片。更改方法: 问题解决....

xingleitinghai的博客 1499

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

OpenCV报错汇总

1、检查文件路径中是否存在中文,如果有,请在英文路径下打开,opencv不支持中文路径!2、重新安装opencv。

m0_56230886的博客 1万+

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

OpenCV2马拉松第4圈——图片混合

下面我进入Sample文件夹下的ImgProc子目录,首先研究下AddingImages.cpp,下面是源代码/** * @file AddingImages.cpp * @brief Simple linear blender ( dst = alpha*src1 + beta*src2 ) * @author OpenCV team */ #include "opencv2/high

abcd1992719g的专栏 1873

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

【opencv报错(已解决)】cv2.error: OpenCV(4.10.0) /Users/runner/work/opencv-python/opencv-python/opencv/modul

在大量查找资料和案例后,下载原本的opencv并重新安装了opencv-contrib-python、opencv-python等opencv库都无法解决上述错误,最后发现了大佬分享的下述方法,十分管用!一击即中,是否有用,推荐大家尝试!

mhatevce的博客 1万+

OpenCV Error: Bad argument

出现原因:在代码中加入平滑函数,出现错误,注释掉平滑函数后,此错误依旧出现 原因分析:位置 解决:尝试重新启动vs2015,未解决 解决:审查代码,平滑代码未注释完全

DashawnTang的博客 4398

(-209:Sizes of input arguments do not match) The operation is neither ‘array op array‘ (where arrays

在利用cv自带的加减乘除对两张图片像素进行操作时,因为其运算原理是通过获取两张(一次只能是两张)图片的同一个位置的色素值来实现运算,所以必须保证两张图片的shape相同。不然会出现以下报错: error: (-209:Sizes of input arguments do not match) The operation is neither ‘array op array’ (where arrays have the same size and the same number of channels).

qq_41202172的博客 1万+

解决调用surf = cv2.xfeatures2d.SURF_create()报错:cv2.error: OpenCV(4.10.0) D:\a\opencv-python\opencv-pytho

然后我都就可以正常运行,大家一定要注意python的版本不能太高,不然还是会报错,为了避免经常报错,一般我创建虚拟环境时都会指定python=3.7。后面发现是在OpenCV 4.0及之后的版本中,SURF和SIFT等专利算法被移至。模块,并且需要额外的配置才能使用。而我的opencv为4.10的。在进行编写特征提取的代码中,使用。和SIFT算法一直报错。这两种写法全部会报错,

m0_63047033的博客 5046

opencv报错cv2.error: OpenCV(4.8.0) D:aopencv-pythonopencv-pythonopencvmodulescoresrcalloc.cpp:

这个错误通常表示你的计算机内存不足,导致OpenCV无法分配需要的内存。优化代码:你也可以检查你的代码是否存在内存泄漏、重复分配内存等问题,并进行优化。

Texh1201的博客 9049

python canny函数_opencvpython cv2.Canny函数的输出Mat对象没有通道信息

我尝试在python中添加两个不同的Mat对象。两个Mat对象都是二进制图像(CV_8U)。但是因为矩阵的大小不一样,所以我在添加它们时得到了一个错误。在我使用numpy为通道生成一个Mat对象,如下所示:diagonal = np.zeros((height,width,1))cv2.line(diagonal,(0,0),(height,width), (255))另一个Mat对象来自cv2。...

weixin_39877166的博客 428

python入门opencv踩过的坑

在用python学习opencv的基本操作时候,dst = cv2.addWeighted(src1, alpha, src2, beta, 0.0)用这个函数总是报错The operation is neither 'array op array' (where arrays have the same size and the same number of channels), nor 'arr

legalhighhigh的博客 6783
上一篇: Python中如何获得数组或者列表按大小排序后元素的索引列表
下一篇: python plt 绘制直方图概率密度和不为1
wzg2016
博客等级 码龄10年 539粉丝 493原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值