小编Pok*_*son的帖子

添加轨迹栏的 OpenCV (Python) 顺序

我正在构建一个带有多个滑块的轨迹栏窗口,如下所示:

import cv2

def do_nothing(_):
    pass

# Create window and add track bars
window_name = 'level control'
cv2.namedWindow(window_name)

for i in xrange(10):
    cv2.createTrackbar(str(i), window_name, 1, 10, do_nothing)

# Wait for escape key
while (True):
    k = cv2.waitKey() & 0xff
    if k == 27:
        break
Run Code Online (Sandbox Code Playgroud)

问题在于它们是以一种非常奇怪的顺序添加的:

在此处输入图片说明

我试图找出模式,所以我将它们一个一个添加。在每一步,它们看起来像:

  • 0
  • 0 1
  • 0 1 2
  • 3 1 2 0 <- 什么?
  • 3 1 4 2 0
  • 3 1 4 2 0 5
  • 3 4 0 5 1 6 2

我想不通模式,但每次都是一样的,所以不是随机的!此外,我添加它们的顺序没有区别,所以它似乎是基于名称。不过,它不是按字母顺序排列的,用字符替换数字给出了类似的顺序(例如d b c …

python user-interface opencv

5
推荐指数
0
解决办法
859
查看次数

为 sklearn 的 GradientBoostingClassifier 生成代码

我想从经过训练的梯度增强分类器(来自 sklearn)生成代码(现在是 Python,但最终是 C)。据我了解,该模型采用初始预测器,然后添加来自顺序训练的回归树的预测(按学习因子缩放)。所选择的类别就是具有最高产出值的类别。

这是我到目前为止的代码:

def recursep_gbm(left, right, threshold, features, node, depth, value, out_name, scale):
    # Functions for spacing
    tabs = lambda n: (' ' * n * 4)[:-1]
    def print_depth():
        if depth: print tabs(depth),
    def print_depth_b():
        if depth: 
            print tabs(depth), 
            if (depth-1): print tabs(depth-1),

    if (threshold[node] != -2):
        print_depth()
        print "if " + features[node] + " <= " + str(threshold[node]) + ":"
        if left[node] != -1:
            recursep_gbm(left, right, threshold, features, left[node], depth+1, value, out_name, scale)
        print_depth()
        print "else:"
        if …
Run Code Online (Sandbox Code Playgroud)

python machine-learning scikit-learn boosting

5
推荐指数
1
解决办法
2932
查看次数