opencv学习----图像位操作(C++)

doesn’t use “mask”

//非操作
bitwise_not(src,des);//two paramaters,the first is the source image,the second is the image of target
//与操作
bitwise_and(src1,src2,des);//three paramaters,the first two paramaters will operater each other and save the lastest image into the third paramaters
//或操作
bitwise_or(src1,src2,des);//three paramaters,the first two paramaters will operater each other and save the lastest image into the third paramaters

The first function is simple ,no need to say more. The principle of the last two functions is that pixels in the first image will operate with these pixels in the second image. Attention!! operations mentioned here is different from its mathematical operation because every pixel’s value is different from 0 to 255,so we can’t use mathematical system to measure this operation.

What is the operation menthoned here? for examples,the first pixel’s value is 150,second pixel’s value is 50,that will give us a new number between 50 to150 rather than return a number between 50 and 150.Please look at the following example:

	Mat mask1 = Mat::zeros(src01.size(),CV_8UC1);
	Mat mask2 = Mat::zeros(src01.size(), CV_8UC1);
	Mat des;
	int high = src01.rows;
	int width = src01.cols;
	for (int row = 0; row < high; row++)
	{
		for (int col = 0; col < width; col++)
		{
			mask1.at<uchar>(row,col) = 150;
			mask2.at<uchar>(row, col) = 90;
		}
	}

	bitwise_or(mask1,mask2,des,Mat());
	imshow("des",des);

The running results are as following:
在这里插入图片描述
The color is exactly what you see.remember it let’s see the next example that modify “mask.at(row,col)” into 90:
在这里插入图片描述
What you find? Yes,the result is a color that hybrid the pixel value of two pixels.So,you probably have known the principles of image bit manipulation without “mask”.

use “mask”

In fact, “mask” has been used in the examples above,First,let’s see the define of “mask”:

Mat mask1 = Mat::zeros(src01.size(),CV_8UC1);
Mat mask2 = Mat::zeros(src01.size(), CV_8UC1);

It is easy,with two caveat:
①:mask’s size must be same with the orinigl image
②:Assuming that two pixels will operator,we should look at the mask’s pixel firstly, if the pixel’s value is 0,the pixel of the goal will be set into 0 ,Only the pixel’s value is not 0,the two pixels could operate each other and save the result into goal’s pixel.

在这里插入图片描述
Look that,when i use “mask” and set every pixels of it into 0,the result is a black box because other two images’ pixels will not operate each other.If you don’t understand, you could leave a comment below.It’s all,thank you!

SERENDIPITY

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 要安装opencv-contrib-python,您可以使用pip命令在命令行中运行以下命令: pip install opencv-contrib-python 这将自动下载和安装最新版本的opencv-contrib-python。请确保您的计算机已连接到互联网,并且您具有管理员权限。如果您遇到任何问题,请尝试使用管理员权限运行命令提示符。 ### 回答2: OpenCV是一款广泛应用于计算机视觉领域的开源库,支持多种编程语言(如C++、Python等)。OpenCV提供了大量的图像和视频处理函数和算法,包括但不限于图像的处理、特征提取、目标检测、人脸识别等功能。 而opencv-contrib-python则是OpenCV官方的扩展包,提供了更多的功能和算法。在使用Python进行图像处理和计算机视觉方面的应用时,opencv-contrib-python是非常重要的一个工具。 安装opencv-contrib-python要考虑多个方面,其中比较重要的两个方面是你所使用的Python版本和操作系统。具体的安装步骤如下: 1. 安装Python 访问Python官网或第三方Python发行版网站,在网站的页面中可以下载Python。根据自己的电脑操作系统和位数下载相应的版本,例如 Windows x64 Installer 这个exe文件即可。 2. 安装OpenCV 在Windows环境下可使用pip install opencv-contrib-python命令进行安装。另外需要注意的是,opencv-contrib-python命令默认会安装OpenCV 3.4.2版本,如果需要安装其他版本则需要加上版本号进行安装。如果没有pip可以去初步下载中默认下载的图形化界面Anaconda Navigator中寻找opencv-contrib-python,选择对应版本进行安装。 在Linux环境下可使用以下命令安装: sudo apt-get update sudo apt-get install python-opencv 3. 测试安装是否成功 打开Python编辑器,在其中输入import cv2即可,如果没有报错说明安装成功了。 总结,opencv-contrib-python在Python的图像处理和计算机视觉方面应用中不可缺少,通过上述安装步骤可以顺利安装并使用它。 ### 回答3: Opencv-contrib-python是Opencv的扩展库,其包含了Opencv官方没有包含的模块,例如SIFT算法等。它提供了方便的接口与脚本语言的接口,对于需要使用这些模块的Python开发者来说很有价值。 在安装opencv-contrib-python之前,需要先安装Opencv。如果已经安装好了Opencv的话,可以先在终端中输入 pip install opencv-contrib-python 来直接安装Opencv-contrib-python。如果还不确定是否安装好了Opencv,可以通过终端中输入下述命令进行确认: import cv2 print(cv2.__version__) 如果上述代码正确执行并输出Opencv的版本号,则表明Opencv已经成功安装。 如果使用的是Anaconda,则可以在终端直接使用命令 conda install opencv-contrib-python 进行安装。如果想要使用末版的opencv-contrib-python,则可以尝试以下代码: pip install opencv-contrib-python-headless 这些命令在安装过程中需要获取一些文件并安装一些依赖包。如果使用的是Python 3,需要确保下载安装的是Python 3.x版的Opencv-contrib-python,否则会出现错误。安装完成后,可以在Python中导入模块并调用其中的函数。 总体而言,Opencv-contrib-python安装比较简单,只需要保证已经正确安装了Opencv,并根据自己的需求选择安装相应的版本即可。安装过程中可能会遇到一些问题,但一般都可以在网络上找到解决方法。如果有更多的问题或者疑惑,在网络或者社区中提出问题是一个不错的选择。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值