Ask Your Question

martyychang's profile - activity

2016-03-24 03:21:38 -0600 received badge  Self-Learner (source)
2016-03-23 19:13:28 -0600 answered a question calcHist() float values in range param?

strann was right. calcHist() does appear to work with negative float32 values, so something else must've been the problem in my code. The simple script below demonstrates calcHist() applied to floating point values in an array, which I tested using Python 2.7.6 and OpenCV 3.1.0 (cv2.__version__).

import cv2
import numpy as np

def print_arr(arr, name='arr'):
    print '{}({}):\n{}'.format(name, arr.dtype, arr)

if __name__ == '__main__':

    # Define an arbitrary 3-D array
    im = np.array(
        [[[1.0, -50.3, 22.3], [-88.2, 30.1, 59.8]],
         [[9.0, 50.3, -22.3], [ -8.2, 90.1, -9.8]]], dtype=np.float32)
    print_arr(im, 'im')

    # Define expected ranges
    images = [im]
    channels = [0, 1, 2]
    mask = None
    histSize = [3, 6, 12]
    ranges = [
        -180.0, 180.0,
        -90.0, 270.0,
        -45.0, 315.0
    ]

    # Calculate the histogram
    hist = cv2.calcHist(images, channels, mask, histSize, ranges)
    print_arr(hist, 'hist')
2016-03-23 19:12:49 -0600 commented question KNearest save problem

Can you clarify what knn.save() and knn.load() are supposed to do? Is the idea to save and load a trained model that would be produced by CvKNearest::train()?

2016-03-22 00:09:49 -0600 asked a question calcHist() float values in range param?

Is the range param in calcHist() supposed to accept and correctly return counts for bins defined using negative float values? As an example, is the following a valid range definition for three dimensions?

range = [
    0, 255,
    -1 * np.pi, np.pi,
    0.0, 255 * np.sqrt(2)
]