Click here to Skip to main content
15,897,187 members
Articles / Desktop Programming / MFC

Detect image skew angle and deskew image

,
Rate me:
Please Sign up or sign in to vote.
4.95/5 (41 votes)
13 Feb 2013CPOL8 min read 233.2K   17K   137  
Deskew an image by converting it to grayscale + edges and rotating by the detected skew angle.
#pragma once


// CTBButton

class CTBButton : public CStatic
{
	DECLARE_DYNAMIC(CTBButton)

public:
	CTBButton();
	virtual ~CTBButton();

	void SetImage(CBitmap* pBitmap, CSize sizeImage, COLORREF clrImgBkgnd = CLR_DEFAULT)
	{
		m_pBitmap = pBitmap;
		m_sizeImage = sizeImage;		
		m_clrImgBkgnd = clrImgBkgnd;

		if(GetSafeHwnd())
		{
			Invalidate();
		}
	}

	CBitmap* GetImage()
	{
		return m_pBitmap;
	}

	CSize GetImageSize()
	{
		return m_sizeImage;
	}

	void SetImageBkgndColor(COLORREF clrImgBkgnd)
	{
		m_clrImgBkgnd = clrImgBkgnd;
		if(GetSafeHwnd())
		{
			Invalidate();
		}
	}

	COLORREF GetImageBkgndColor()
	{
		return m_clrImgBkgnd;
	}

	

protected:
	DECLARE_MESSAGE_MAP()

	COLORREF m_clrImgBkgnd;
	CSize m_sizeImage;

	CBitmap* m_pBitmap;

	BOOL m_bTracking;
	BOOL m_bDragging;

public:
	afx_msg void OnPaint();
	afx_msg void OnStnClicked();
protected:
	virtual void PreSubclassWindow();
public:
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
	afx_msg void OnTimer(UINT_PTR nIDEvent);
	afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
};


By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Technical Lead Kotha Technologies
Bangladesh Bangladesh
If you are not in - you are out !
- Chapter 1

Written By
Network Administrator
Australia Australia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions