opencv 随笔

 

装环境好累,python3.6,opencv3.4

好不容易装好了,结果

addweight的时候总是报错

The operation is neither 'array op array' (where arrays have the same size and the same number of channels), nor 'array op scalar', nor 'scalar op array' in function cv::arithm_op

开始看到有人说时图片大小不一致的原因我还不信,因为我第二张图是基于第一张180度翻转得到的,我寻思着肯定一样大吧

然后print一下shape

print(img1.shape, img2.shape)

吐血

期间我换成py2.7,重装了一次opencv2.4版本

于是总算懂得resize一下

 

 

 1 import cv2
 2 
 3 #加载图片
 4 img1 = cv2.imread('1.jpg')
 5 img2 = cv2.imread('2.jpg')
 6 
 7 #求img1的height 和 wide
 8 h, w, _ = img1.shape
 9 #这里打印出来检测一下是否size不同
10 print(img1.shape, img2.shape)
11 
12 #将img2进行缩放,注意这里的resize中(顺序是宽高)和shape出来的不一样
13 img2 = cv2.resize(img2, (w,h), interpolation=cv2.INTER_AREA)
14 
15 #设定权重
16 alpha = 0.5
17 beta = 1-alpha
18 gamma = 0
19 
20 #开始叠加
21 img_add = cv2.addWeighted(img1, alpha, img2, beta, gamma)
22 
23 #创建一个名为‘add’的窗口用来展示
24 cv2.imshow('add',img_add)
25 
26 #等待键入,按任意键退出全部窗口
27 cv2.waitKey(0)
28 cv2.destroyAllWindows()

原图是:

官方教程是这样的:

img1 = cv2.imread('ml.png')
img2 = cv2.imread('opencv_logo.jpg')dst = cv2.addWeighted(img1,0.7,img2,0.3,0)cv2.imshow('dst',dst)
cv2.waitKey(0)
cv2.destroyAllWindows()

然而人家的俩图尺寸一毛一样

修改后应该是这样

import cv2
img1 = cv2.imread("1.jpg")
img2 = cv2.imread("2.jpg")
h, w, _ = img1.shape
img2=cv2.resize(img2,(w,h),interpolation=cv2.INTER_AREA)
dst = cv2.addWeighted(img1,0.7,img2,0.3,0)
cv2.imshow("dst",dst)
cv2.waitKey(0)
cv2.destroyAllWindows()

 

转载于:https://www.cnblogs.com/mrfri/p/8541998.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/391058.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

中小型研发团队架构实践三要点(转自原携程架构师张辉清)

如果你正好处在中小型研发团队…… 中小型研发团队很多,而社区在中小型研发团队架构实践方面的探讨却很少。中小型研发团队特别是 50 至 200 人的研发团队,在早期的业务探索阶段,更多关注业务逻辑,快速迭代以验证商业模式&#xf…

时间序列预测 预测时间段_应用时间序列预测:美国住宅

时间序列预测 预测时间段1.简介 (1. Introduction) During these COVID19 months housing sector is rebounding rapidly after a downtime since the early months of the year. New residential house construction was down to about 1 million in April. As of July 1.5 mi…

zabbix之web监控

Web monitoring(web监控)是用来监控Web程序的,可以监控到Web程序的下载速度,返回码以及响应时间,还支持把一组连续的Web动作作为一个整体进行监控。 1.Web监控的原理 Web监控即对HTTP服务的监控,模拟用户去访问网站,对…

经验主义 保守主义_为什么我们需要行动主义-始终如此。

经验主义 保守主义It’s been almost three months since George Floyd was murdered and the mass protests. Three months since the nationwide protests, looting and riots across America.距离乔治弗洛伊德(George Floyd)被谋杀和大规模抗议活动已经快三个月了。 全国抗议…

redis介绍以及安装

一、redis介绍 redis是一个key-value存储系统。和Memcached类似,它支持存储的values类型相对更多,包括字符串、列表、哈希散列表、集合,有序集合。 这些数据类型都支持push/pop、add/remove及取交集并集和差集及更丰富的操作,而且…

python机器学习预测_使用Python和机器学习预测未来的股市趋势

python机器学习预测Note from Towards Data Science’s editors: While we allow independent authors to publish articles in accordance with our rules and guidelines, we do not endorse each author’s contribution. You should not rely on an author’s works withou…

Python数据结构之四——set(集合)

Python版本:3.6.2 操作系统:Windows 作者:SmallWZQ 经过几天的回顾和学习,我终于把Python 3.x中的基础知识介绍好啦。下面将要继续什么呢?让我想想先~~~嗯,还是先整理一下近期有关Python基础知识的随笔吧…

knn 机器学习_机器学习:通过预测意大利葡萄酒的品种来观察KNN的工作方式

knn 机器学习Introduction介绍 For this article, I’d like to introduce you to KNN with a practical example.对于本文,我想通过一个实际的例子向您介绍KNN。 I will consider one of my project that you can find in my GitHub profile. For this project, …

python 实现分步累加_Python网页爬取分步指南

python 实现分步累加As data scientists, we are always on the look for new data and information to analyze and manipulate. One of the main approaches to find data right now is scraping the web for a particular inquiry.作为数据科学家,我们一直在寻找…

关于双黑洞和引力波,LIGO科学家回答了这7个你可能会关心的问题

引力波的成功探测,就像双黑洞的碰撞一样,一石激起千层浪。 关于双黑洞和引力波,LIGO科学家回答了这7个你可能会关心的问题 最近,引力波的成功探测,就像双黑洞的碰撞一样,一石激起千层浪。 大家兴奋之余&am…

用于MLOps的MLflow简介第1部分:Anaconda环境

在这三部分的博客中跟随了演示之后,您将能够: (After following along with the demos in this three part blog you will be able to:) Understand how you and your Data Science teams can improve your MLOps practices using MLflow 了解您和您的数…

pymc3 贝叶斯线性回归_使用PyMC3估计的贝叶斯推理能力

pymc3 贝叶斯线性回归内部AI (Inside AI) If you’ve steered clear of Bayesian regression because of its complexity, this article shows how to apply simple MCMC Bayesian Inference to linear data with outliers in Python, using linear regression and Gaussian ra…

mongodb分布式集群搭建手记

一、架构简介 目标 单机搭建mongodb分布式集群(副本集 分片集群),演示mongodb分布式集群的安装部署、简单操作。 说明 在同一个vm启动由两个分片组成的分布式集群,每个分片都是一个PSS(Primary-Secondary-Secondary)模式的数据副本集; Confi…

python16_day37【爬虫2】

一、异步非阻塞 1.自定义异步非阻塞 1 import socket2 import select3 4 class Request(object):5 def __init__(self,sock,func,url):6 self.sock sock7 self.func func8 self.url url9 10 def fileno(self): 11 return self.soc…

朴素贝叶斯实现分类_关于朴素贝叶斯分类及其实现的简短教程

朴素贝叶斯实现分类Naive Bayes classification is one of the most simple and popular algorithms in data mining or machine learning (Listed in the top 10 popular algorithms by CRC Press Reference [1]). The basic idea of the Naive Bayes classification is very …

2019年度年中回顾总结_我的2019年回顾和我的2020年目标(包括数量和收入)

2019年度年中回顾总结In this post were going to take a look at how 2019 was for me (mostly professionally) and were also going to set some goals for 2020! 🤩 在这篇文章中,我们将了解2019年对我来说(主要是职业)如何,我们还将为20…

vray阴天室内_阴天有话:第1部分

vray阴天室内When working with text data and NLP projects, word-frequency is often a useful feature to identify and look into. However, creating good visuals is often difficult because you don’t have a lot of options outside of bar charts. Lets face it; ba…

高光谱图像分类_高光谱图像分析-分类

高光谱图像分类初学者指南 (Beginner’s Guide) This article provides detailed implementation of different classification algorithms on Hyperspectral Images(HSI).本文提供了在高光谱图像(HSI)上不同分类算法的详细实现。 目录 (Table of Contents) Introduction to H…

机器人的动力学和动力学联系_通过机器学习了解幸福动力学(第2部分)

机器人的动力学和动力学联系Happiness is something we all aspire to, yet its key factors are still unclear.幸福是我们所有人都渴望的东西,但其关键因素仍不清楚。 Some would argue that wealth is the most important condition as it determines one’s li…

ubuntu 16.04 安装mysql

2019独角兽企业重金招聘Python工程师标准>>> 1) 安装 sudo apt-get install mysql-server apt-get isntall mysql-client apt-get install libmysqlclient-dev 2) 验证 sudo netstat -tap | grep mysql 如果有 就代表已经安装成功。 3)开启远程访问 1、 …