使用javacv来实现灰度直方图的绘制,calchist函数运行出错

//绘制灰度直方图
public static void drawHistImage()
{

    IntPointer channels = new IntPointer(0);
    IntPointer histSize = new IntPointer(256);
    FloatPointer histRange = new FloatPointer(0,256);

    Mat hist = new Mat();
    //计算直方图
    calcHist((grayContour.get())[0], 1,channels, new Mat(), hist, 1,histSize, histRange);

    //按行归一化
    normalize(hist, hist, 0, hist.rows() ,NORM_MINMAX, -1, new Mat());
    ...
}

代码在calchist处出错:(-215:Assertion failed) j < nimages in function 'cv::histPrepareImages',请问如何解决,感谢回答!