opencv 3/C+직사 도 역방향 투영 인 스 턴 스

직사 도 역방향 투영:
즉,직사 도 중의 값 을 취하 고 직사 도 면적 에 따라 큰 것 에서 작은 것 으로 대응 하 는 픽 셀 도 큰 것 에서 작은 것 으로 새로운 값 을 부여 하 는 것 이다.즉,특정한 그 레이스 케 일 값 이 이미지 에서 차지 하 는 면적 이 클 수록 해당 하 는 픽 셀 의 새로운 값 이 커진다.반대로 작 을 수록

void calcBackProject( 
const Mat* images, //   /  ;         (CV_8U CV_32F)。
int nimages,//      
const int* channels, //          ;               。
InputArray hist,//     。
OutputArray backProject, //        , images[0]  、          。
const float** ranges,//        bin    。
double scale = 1, //             。
bool uniform = true //          。
);
예시:
테스트 그림 의 픽 셀 마다 hue 데이터 hi,j 를 가 져 오고 hi,j 가 hue 직사 도 에 있 는 bin 의 위 치 를 찾 습 니 다.

#include<opencv2/opencv.hpp>
using namespace cv;

Mat hue;
int bins = 10;
void histBackprojection(int, void*);
int main()
{
 Mat src, hsv;
 src = imread("E:/image/image/shape.jpg");
 if (src.empty())
 {
  printf("can not load image 
"); return -1; } namedWindow("input", WINDOW_AUTOSIZE); imshow("input", src); cvtColor(src, hsv, COLOR_BGR2HSV); hue.create(hsv.size(), hsv.depth()); int ch[] = {0, 0}; // Hue : mixChannels(&hsv, 1, &hue, 1, ch, 1); // Trackbar bin createTrackbar("bins:", "input", &bins, 255, histBackprojection); histBackprojection(0, 0); waitKey(0); return 0; } void histBackprojection(int, void*) { MatND hist, backproj; int histSize = max(bins, 2); float range[] = {0, 255}; const float *ranges = {range}; // calcHist(&hue, 1, 0, Mat(), hist,1, &histSize, &ranges, true, false); // bin 0-255 normalize(hist, hist, 0, 255, NORM_MINMAX, -1, Mat()); // calcBackProject(&hue, 1, 0, hist, backproj, &ranges, 1, true); namedWindow("backprogection", WINDOW_AUTOSIZE); imshow("backprogection", backproj); // int binsW = cvRound((double)500/histSize); Mat histImg = Mat::zeros(500, 500, CV_8UC3); RNG rng(123); for (int i = 0; i < bins; i++) { Scalar color = Scalar(rng.uniform(0,255),rng.uniform(0,255),rng.uniform(0,255)); rectangle(histImg, Point(i*binsW, 500), Point((i+1)*binsW, 500 - cvRound(hist.at<float>(i) * 500 / 255.0)), color, -1); } namedWindow("histogram", WINDOW_AUTOSIZE); imshow("histogram", histImg); }






이상 의 opencv 3/C+직사 도 역방향 투영 인 스 턴 스 는 바로 소 편 이 여러분 에 게 공유 한 모든 내용 입 니 다.여러분 께 참고 가 되 고 저 희 를 많이 사랑 해 주 셨 으 면 좋 겠 습 니 다.

좋은 웹페이지 즐겨찾기