int ImageRep::MeanHsv(const IntRect& rRect, int channel) const { assert(rRect.XMin() >= 0 && rRect.YMin() >= 0 && rRect.XMax() <= m_images[0].cols && rRect.YMax() <= m_images[0].rows); int sum_v = m_integralHsvImages[channel].at<int>(rRect.YMin(), rRect.XMin()) + m_integralHsvImages[channel].at<int>(rRect.YMax(), rRect.XMax()) - m_integralHsvImages[channel].at<int>(rRect.YMax(), rRect.XMin()) - m_integralHsvImages[channel].at<int>(rRect.YMin(), rRect.XMax()); return sum_v / rRect.Area(); }
void HsvFeatures::UpdateFeatureVector(const Sample &s) { IntRect rect = s.GetROI(); cv::Rect roi(rect.XMin(), rect.YMin(), rect.Width(), rect.Height()); m_featVec.setZero(); cv::Mat hsv_img = s.GetImage().GetHsvImage()(roi); int height = rect.Height(); int width = rect.Width(); // continuous? if(hsv_img.isContinuous()) { width *= height; height = 1; } int ix, iy; uchar *p; for(iy=0; iy < height; ++iy) { p = hsv_img.ptr<uchar>(iy); for(ix=0; ix < width; ++ix) { cv::Vec3b pixel(p[3*ix+0], p[3*ix+1], p[3*ix+2]); auto bin_idx = compBinIdx(pixel); m_featVec[bin_idx]++; } } m_featVec /= rect.Area(); }
void ImageRep::Hist(const IntRect& rRect, Eigen::VectorXd& h) const { assert(rRect.XMin() >= 0 && rRect.YMin() >= 0 && rRect.XMax() <= m_images[0].cols && rRect.YMax() <= m_images[0].rows); int norm = rRect.Area(); for (int i = 0; i < kNumBins; ++i) { int sum = m_integralHistImages[i].at<int>(rRect.YMin(), rRect.XMin()) + m_integralHistImages[i].at<int>(rRect.YMax(), rRect.XMax()) - m_integralHistImages[i].at<int>(rRect.YMax(), rRect.XMin()) - m_integralHistImages[i].at<int>(rRect.YMin(), rRect.XMax()); h[i] = (float)sum/norm; } }
bool PalettedRectIsSolidColor(Decoder* aDecoder, const IntRect& aRect, uint8_t aColor) { RawAccessFrameRef currentFrame = aDecoder->GetCurrentFrameRef(); uint8_t* imageData; uint32_t imageLength; currentFrame->GetImageData(&imageData, &imageLength); ASSERT_TRUE_OR_RETURN(imageData, false); // Clamp to the frame rect. If any pixels outside the frame rect are included, // we immediately fail, because such pixels don't have any "color" in the // sense this function measures - they're transparent, and that doesn't // necessarily correspond to any color palette index at all. IntRect frameRect = currentFrame->GetRect(); ASSERT_EQ_OR_RETURN(imageLength, uint32_t(frameRect.Area()), false); IntRect rect = aRect.Intersect(frameRect); ASSERT_EQ_OR_RETURN(rect.Area(), aRect.Area(), false); // Translate |rect| by |frameRect.TopLeft()| to reflect the fact that the // frame rect's offset doesn't actually mean anything in terms of the // in-memory representation of the surface. The image data starts at the upper // left corner of the frame rect, in other words. rect -= frameRect.TopLeft(); // Walk through the image data and make sure that the entire rect has the // palette index |aColor|. int32_t rowLength = frameRect.width; for (int32_t row = rect.y; row < rect.YMost(); ++row) { for (int32_t col = rect.x; col < rect.XMost(); ++col) { int32_t i = row * rowLength + col; ASSERT_EQ_OR_RETURN(aColor, imageData[i], false); } } return true; }