简体   繁体   English

如何使用 cv2 python API 使用 opencv reduce

[英]How to use opencv reduce using cv2 python API

I checked the documentation but its incomplete: there is no mention of what rtype parameter actually is.我检查了文档,但它不完整:没有提到rtype参数实际上是什么。

I think it's a reduce type but I can't find any of variables like cv2.CV_REDUCE_SUM etc... I found this problem with many function that use different variable names.我认为这是一种减少类型,但我找不到任何变量,如cv2.CV_REDUCE_SUM等......我发现这个问题与许多使用不同变量名的函数有关。 What's the best way to find proper names in cv2 API?在 cv2 API 中找到正确名称的最佳方法是什么?

I found out that the appropriate variable can be found in the following package我发现可以在以下包中找到适当的变量

cv2.cv

If you use CV_REDUCE_SUM operator on uint8 image you have to explicitly provide dtype parameter of bigger range to avoid overflowing (eg如果在uint8图像上使用 CV_REDUCE_SUM 运算符,则必须显式提供更大范围的 dtype 参数以避免溢出(例如

slice = cv2.reduce(image, 1, cv2.cv.CV_REDUCE_SUM, dtype=numpy.int32)

If you use CV_REDUCE_AVG operation, result can't overflow that's why setting dtype is optional.如果您使用 CV_REDUCE_AVG 操作,结果不会溢出,这就是为什么设置 dtype 是可选的。

There are some omisions in the current new cv2 lib.当前新的 cv2 库中有一些遗漏。 Typically these are constants that did not get migrated to cv2 yet and are still in cv only.通常这些是尚未迁移到 cv2 并且仍仅在 cv 中的常量。 Here is some code to help you find them:这里有一些代码可以帮助您找到它们:

import cv2
import cv2.cv as cv
nms  = [(n.lower(), n) for n in dir(cv)] # list of everything in the cv module
nms2 = [(n.lower(), n) for n in dir(cv2)] # list of everything in the cv2 module

search = 'window'

print "in cv2\n ",[m[1] for m in nms2 if m[0].find(search.lower())>-1]
print "in cv\n ",[m[1] for m in nms if m[0].find(search.lower())>-1]

If you're finding this while using Open CV 3.x or later, these constants have been renamed to cv2.REDUCE_SUM , cv2.REDUCE_AVG , cv2.REDUCE_MAX , and cv2.REDUCE_MIN .如果您在使用 Open CV 3.x 或更高版本时发现此问题,这些常量已重命名为cv2.REDUCE_SUMcv2.REDUCE_AVGcv2.REDUCE_MAXcv2.REDUCE_MIN

An example of the working reduce function:一个工作reduce函数的例子:

reducedArray = cv2.reduce(im, 0, cv2.REDUCE_MAX)

GitHub issue for documentation文档的 GitHub 问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM