Belirli bir renk aralığındaki piksel sayısını hesaplamak istiyorum calcHist. Ancak şu hataları alıyorum:CalcHist'i belirli bir resim aralığındaki piksel sayısını üretmek için kullanmak istediğimde onaylanmadı
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace std;
using namespace cv;
int main(int argc, const char** argv) {
Mat image = imread("D:\\obj\\138.jpg");
Mat img_hsv;
cvtColor(image, img_hsv, CV_BGR2HSV);
int hbins = 1;
int sbins = 1;
int vbins = 1;
int histSize[] = { hbins,sbins,vbins };
//H
float hranges[] = { 0,20 };
//S
float sranges[] = { 100,255 };
//V
float vranges[] = { 107,245 };
const float* ranges[] = { hranges,sranges,vranges };
MatND hist;
//chanels
int channels[] = { 0,1,2 };
calcHist(&img_hsv, 1, channels, Mat(), hist, 3, histSize, ranges);
cout << "Hist.dims = " << hist.dims << endl;
cout << "Value: " << hist.at<double>(0) << endl;
cout << "Hist.rows = " << hist.rows << endl;
cout << "Hist.cols = " << hist.cols << endl;
return 0;
}
Ben resmi öğretici kod adapte:
OpenCV Error: Assertion failed (dims <= 2 && data && (unsigned)i0 < (unsigned)(size.p[0]*size.p[1]) && elemSize() == (((((DataType<_Tp>::type) & ((512 - 1) << 3)) >> 3) + 1) << ((((sizeof(size_t)/4+1)*16384|0x3a50) >> ((DataType<_Tp>::type) & ((1 << 3) - 1))*2) & 3))) in cv::Mat::at, file e:\opencv2.4\opencv\build\include\opencv2\core\mat.hpp, line 570
ZKB_shop.exe has triggered a breakpoint.
Kodum aşağıdakilerden gibi gösterir http://docs.opencv.org/3.1.0/d6/dc7/group__imgproc__hist.html#ga4b2b5fd75503ff9e6844cc4dcdaed35d ve eklemek bir daha kanala ama o değil neden hiçbir fikrim yok Çalışıyorum
Ben VS2015 + WIN10 + OPENCV2.4.11