Reputation: 5432
I'm trying to subdivide a gray frame in multiple small squares and than caluculate for each one of them the mean color value of each one so I can build a result frame that display those values, here 's what I' done :
int main (){
cv::Mat frame= cv::imread("test2.jpg",0), result, myROI;
int key = 0;
int roiSize =10;
cv::Scalar mean(0);
cv::Mat meanS;
meanS = cv::Mat::zeros (frame.rows/roiSize,frame.cols/roiSize,CV_32FC1) ;
cv::Rect roi;
if(frame.channels()!=1)
cv::cvtColor(frame,frame,CV_BGR2GRAY);
for ( int i=0 ; i< frame.cols /roiSize; i++){
for (int j = 0 ; j < frame.rows/roiSize; j++){
roi.x= i*roiSize;
roi.y= j*roiSize;
roi.height=roiSize;
roi.width= roiSize;
myROI = frame(roi);
cv::imshow("myRoi",myROI);
mean = cv::mean(myROI);
std::cout << mean[0] << std::endl;
meanS.at<float>(j,i) = mean[0];
}
}
//meanS *=1/255; // I've tried this one also, it didn't help !
cv::imshow("the reuslt ",meanS);
cv::waitKey(0);
return 0;
}
in the console the values are correct but when I display the result with imshow
I get only a white frame ! !!
any Idea how can I solve this ?
thanks in advance !
Upvotes: 0
Views: 123
Reputation: 5708
your comment line is actually correct but it's doing integer division and thus multiplying by zero. just add a dot at the end like meanS *=1/255.; // I've tried this one also, it didn't help !
Upvotes: 3