C ++ |使用setTo更改cv :: mat中的颜色 [英] C++ | Change color in cv::mat with setTo

查看:1265
本文介绍了C ++ |使用setTo更改cv :: mat中的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个cv :: Mat文件与vec3b值。这些值是图像的颜色。我想更改图像中的一些颜色。

I have a cv::Mat file with vec3b values. These values are colours from an image. I'd like to change some colours in that image.

我知道setTo()函数的正常矩阵操作,但如何使用它为我的Mat文件?

I know the setTo() function for normal matrix manipulation, but how do I use it for my Mat file?

我试过这样:

 image = image.setto(Vec3b(0,0,0), image == Vec3b(255,0,0))

Thx!

推荐答案

给定一个图像 image image 中等于 Scalar(255,0,0)的所有像素,然后将这些像素设置为 Scalar(0,0,0)

Given an image image, we want to find all the pixels in image that are equal to Scalar(255,0,0) and then set these pixels to Scalar(0,0,0).


  • 首先,我们需要获取 mask 如果 image中的相应位置等于 Scalar(255,0,...),则 mask 0),否则设置为0.这可以通过 inRange() 函数。

  • First we need to obtain mask, such that a location in mask is set to 255 if the corresponding location in image equals Scalar(255,0,0), otherwise it is set to 0. This can be achieved with inRange() function.

Mat mask;
inRange(image, Scalar(255,0,0), Scalar(255,0,0), mask);


<函数到 image

image.setTo(Scalar(0,0,0), mask);


这篇关于C ++ |使用setTo更改cv :: mat中的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆