以下のコードを見てください
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace std;
using namespace cv;
Mat image,image_clone,testImage,testImageHSV,imageHSV,testImageHue,imageHue;
int ch[] = {0,0};
int bins=10;
char *windowName = "BackProjection";
void histAndBackProjection(int,void*);
int main()
{
//Load the image
image = imread("E:/Trip/DSC01894.jpg");
image_clone ;
image.copyTo(image_clone);
//Break a small piece from the image
testImage = image(Rect(450,470,20,20));
cv::rectangle(image_clone,Point(450,470),Point(500,500),Scalar(255,0,0),2);
//Transfor to HSV
cvtColor(testImage,testImageHSV,CV_BGR2HSV);
cvtColor(image,imageHSV,CV_BGR2HSV);
//Seperate the HUE channel
testImageHue.create(testImageHSV.size(),testImageHSV.depth());
imageHue.create(imageHSV.size(),imageHSV.depth());
cv::mixChannels(&testImageHSV,1,&testImageHue,1,ch,1);
cv::mixChannels(&imageHSV,1,&imageHue,1,ch,1);
namedWindow("Image");
imshow("Image",image_clone);
namedWindow("Test Image");
imshow("Test Image",testImage);
//Creating windows for trackbar
namedWindow(windowName);
//Creating the track bar
createTrackbar("Select Bins",windowName,&bins,255,histAndBackProjection);
histAndBackProjection(0,0);
waitKey(0);
return 0;
}
void histAndBackProjection(int, void *)
{
MatND histImage,backProjection;
int histSize = MAX(bins,2);
float range[]={0,180};
const float* rangePtr={range};
//Calculate the histogram
cv::calcHist(&testImageHue,1,0,Mat(),histImage,1,&histSize,&rangePtr,true,false);
cv::normalize(histImage,histImage,1.0);
//Do the backprojection
cv::calcBackProject(&imageHue,1,0,histImage,backProjection,&rangePtr,1,true);
imshow(windowName,backProjection);
}
このコードを逆投影に使用しています。しかし、私の逆投影出力は 100% 黒です! スライダーをどこに動かしても真っ黒!私の画像では、白い領域を見つける必要があるため、100% 白い場所を逆投影することを目標としています。
どうしてこれなの?コードに問題はありますか?