void DoPaint() { RECT rcClient = { 0 }; ::GetClientRect(m_hWnd, &rcClient); DWORD dwWidth = rcClient.right - rcClient.left; DWORD dwHeight = rcClient.bottom - rcClient.top; HDC hDcPaint = ::GetDC(m_hWnd); HDC hDcBackground = ::CreateCompatibleDC(hDcPaint); COLORREF* pBackgroundBits; HBITMAP hbmpBackground = CreateMyBitmap(hDcPaint, dwWidth, dwHeight, &pBackgroundBits); ::ZeroMemory(pBackgroundBits, dwWidth * dwHeight * 4); HBITMAP hOldBitmap = (HBITMAP)::SelectObject(hDcBackground, hbmpBackground); SetBkMode(hDcBackground, OPAQUE); m_pm.GetRoot()->SetPos(rcClient); m_pm.GetRoot()->DoPaint(hDcBackground, rcClient); PaintArrow(hDcBackground, rcClient); ResetAlpha((BYTE*)pBackgroundBits, dwWidth, dwHeight); RECT rcWnd = { 0 }; ::GetWindowRect(m_hWnd, &rcWnd); BLENDFUNCTION bf = { AC_SRC_OVER, 0, 255, AC_SRC_ALPHA }; POINT ptPos = { rcWnd.left, rcWnd.top }; SIZE sizeWnd = { dwWidth, dwHeight }; POINT ptSrc = { 0, 0 }; UpdateLayeredWindow(m_hWnd, hDcPaint, &ptPos, &sizeWnd, hDcBackground, &ptSrc, 0, &bf, ULW_ALPHA); ::SelectObject(hDcBackground, hOldBitmap); if (hDcBackground != NULL) ::DeleteDC(hDcBackground); if (hbmpBackground != NULL) ::DeleteObject(hbmpBackground); ::ReleaseDC(m_hWnd, hDcPaint); }
void Compute(ImageF& image) { const int nx = image.GetWidth(); const int ny = image.GetHeight(); const int len = *gvRoiSize; // Compute gradients gradients.Compute(image); MatF& magsqr = gradients.magnitude_sqr; magsqr /= magsqr.MaxValue(); // Create the histogram votes.Resize(ny, nx, *gvThetaBins); // Compute the (theta,rho,phi) histogram for (int y = roi.Top(); y < roi.Bottom(); y++) { const float* orientrow = orient[y]; const float* magrow = magsqr[y]; for (int x = roi.Left(); x < roi.Right(); x++) { if (mask[y-roi.Top()][x-roi.Left()]) { const float theta = OpenUpAngle(orientrow[x]); const float rho = (x-cx) * cos(theta) + (y-cy) * sin(theta); const int theta_bin = ThetaToBin(theta); const int rho_bin = RhoToBin(rho); const float mag = sqrtf(magrow[x]); hist[theta_bin][rho_bin] += mag; } } } // Find edgels int nn = 0; for (int y = 0; y < hist.Rows(); y++) { for (int x = 0; x < hist.Cols(); x++) { if (hist[y][x] >= *gvThresh) { const float theta = BinToTheta(y); const float rho = BinToRho(x); const float costh = cos(theta); const float sinth = sin(theta); const Vec3F line(costh, sinth, -cx*costh - cy*sinth - rho); Edgel cur(theta, rho, hist[y][x], line); ClipLineToROI(cur.line, roi, cur.start, cur.end); edgels.push_back(cur); } } } int main(int argc, char **argv) { InitVars(argc, argv, "edgels.cfg"); ImageF image; ImageRGB<byte> imagergb; ReadImage(argv[1], imagergb); ImageCopy(imagergb, image); ResetAlpha(imagergb); const int nx = image.GetWidth(); const int ny = image.GetHeight(); Edgels edgels(image); DREPORT(edgels.edgels.size()); ImageRGB<byte> canvas; ImageCopy(imagergb, canvas); BrightColors colors; BOOST_FOREACH(const Edgel& e, edgels.edgels) { e.Draw(canvas, colors.Next()); } WriteImage("out/all_edgels.png", canvas); return 0; }