2017-03-12 2 views
0

J'essaye de créer un histogramme pour la projection arrière d'une image en utilisant le wrapper Emgu C# pour OpenCV. Je le code suivant OpenCV C++ que je suis en train de se convertir à Emgu C#:Emgu - CalcHist _rowRange erreur

char* filename = (char*)"C:\\Images\\items.jpg"; 
Mat im = imread(filename); 
if (im.empty()) 
    return -1; 

const int channels[] = { 0, 1, 2 }; 
const int histSize[] = { 32, 32, 32 }; 
const float rgbRange[] = { 0, 256 }; 
const float* ranges[] = { rgbRange, rgbRange, rgbRange }; 

Mat hist; 
Mat im32fc3, backpr32f; 

im.convertTo(im32fc3, CV_32FC3); 
calcHist(&im32fc3, 1, channels, Mat(), hist, 3, histSize, ranges, true, false); 
calcBackProject(&im32fc3, 1, channels, hist, backpr32f, ranges); 

Emgu C# conversion:

string filename = @"C:\Images\items.jpg"; 
Mat im = CvInvoke.Imread(filename); 
if (im.IsEmpty) 
{ 
    return -1; 
} 

int[] channels = { 0, 1, 2 }; 
int[] histSize = { 32, 32, 32 }; 
float[] ranges = { 0.0f, 256.0f, 0.0f, 256.0f, 0.0f, 256.0f }; 

Mat im32fc3 = new Mat(); 
Mat hist = new Mat(); 
Mat mask = new Mat(); 
Mat backpr32f = new Mat(); 

im.ConvertTo(im32fc3, Emgu.CV.CvEnum.DepthType.Cv32F); 
CvInvoke.CalcHist(im32fc3, channels, mask, hist, histSize, ranges, false); 
CvInvoke.CalcBackProject(im32fc3, channels, hist, backpr32f, ranges); 

Cependant, je reçois l'erreur suivante à CvInvoke.CalcHist:

OpenCV: 0 = < _rowRange.start & & _rowRange.start < = _rowRange.end & & _rowRange.end < = m.rows

Toute aide est appréciée.

Répondre

0

J'ai eu le même problème. trouvé ce morceau de code dans emgu VS solution.

 using (Util.VectorOfMat vm = new Util.VectorOfMat()) 
     { 
      vm.Push(channels[i]); 
      float[] ranges = new float[] { minVal, maxVal }; 
      CvInvoke.CalcHist(vm, new int[] { 0 }, null, hist, new int[] { numberOfBins }, ranges, false); 
     } 

utilisation VectorOfMat pour le 1er arugment au lieu de Mat.