在 OpenCV 中是按位掩码和操作 [英] in OpenCV is mask a bitwise and operation

查看:73
本文介绍了在 OpenCV 中是按位掩码和操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从 python 中的 opencv 开始,我有一个关于如何应用掩码的问题

I'm starting with opencv in python and I have a questions about how mask is applied for

bitwise_and(src1, src2, mask=mask)

以下哪些描述了实现:

  • A.全部按位,先屏蔽

  • A. all bitwise, mask first

  1. src1 与掩码进行 AND 运算
  2. src2 与掩码进行 AND 运算
  3. src1 和 src2 剩下的部分被 AND 连接在一起

  • B.所有按位,图像优先

  • B. all bitwise, images first

    1. src1 与 src2 进行 AND 运算
    2. 结果与掩码相加

  • C.条件 AND

  • C. conditional AND

    1. 掩码通过(例如循环)迭代"
    2. 对于掩码中的每个像素,如果它不为零,则将 src1,src2 中的相应像素与并复制到输出

  • 我认为每个的性能特征可能略有不同.

    I would think the performance characteristics of each could vary slightly.

    其中哪些(或其他方式)是实际实现?(以及为什么,如果我可以问)

    Which of these (or how else) is the actual implementation? (and why, if I may ask)

    我试图查看源代码,但无法完全弄清楚他们做了什么:https://github.com/opencv/opencv/blob/ca0b6fbb952899a1c7de91b909d3acd8e682cedf/modules/core/src/arithm.cpp

    I was trying to look at the source, but couldn't quite make out what they did: https://github.com/opencv/opencv/blob/ca0b6fbb952899a1c7de91b909d3acd8e682cedf/modules/core/src/arithm.cpp

    推荐答案

    如果您查看文档,第三个参数是您错过的目标图像.

    If you look at the docs, the 3rd parameter is a destination image which you missed.

    此操作仅在掩码说明时更改目标图像的值(在这种情况下,它将执行两个源图像的按位和).对于不在掩码中的像素,目标将包含它之前包含的相同值.

    This operation will change the values of the destination image only if the mask says so (in this case it will do the bitwise and of the two source images). For the pixels that are not in the mask, the destination will contain the same values that it contained before.

    这篇关于在 OpenCV 中是按位掩码和操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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