1

Topic: Finding and object turn on OpenCV

Kind time of days! The task: On a photo there is a rectangular form document. The document can lie under any corner. It is necessary for me to turn the document exactly. Also it is necessary to cut off all superfluous background. Earlier never with a drawing worked and there is no time fully in it to understand. Here that made: uses System. SysUtils, ocv.highgui_c, ocv.core_c, ocv.core.types_c, ocv.imgproc_c, ocv.imgproc.types_c, ocv.tracking_c, ocv.lib; var img, img_new, img_res: pIplImage; storage: pCvMemStorage = nil; contours: pCvSeq = nil; curr_cont, bigest_contur, bigest_contur2: pCvSeq; ploshad, curr_ploshad: Double; begin img: = cvLoadImage (' C:\1.jpg '); img_new: = cvCreateImage (cvGetSize (img), IPL_DEPTH_8U, 1); img_res: = cvCreateImage (cvGetSize (img), IPL_DEPTH_8U, 1);//Translated in it is black white cvCvtColor (img, img_new, CV_RGB2GRAY);//Drew all boundaries cvCanny (img, img_new, 100, 200, 3); //I Search for circuits on drawn by a method cvCanny boundaries storage: = cvCreateMemStorage (0); contours: = AllocMem (SizeOf (TCvSeq)); cvFindContours (img_new, storage, @contours, SizeOf (TCvContour), CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE, cvPoint (0, 0));//Now I try to find a circuit with the greatest area bigest_contur: = nil; curr_cont: = contours; curr_ploshad: = 0; while (curr_cont <> nil) do begin ploshad: = Abs (cvContourArea (curr_cont, CV_WHOLE_SEQ)); if curr_ploshad <ploshad then begin bigest_contur: = curr_cont; curr_ploshad: = ploshad; end; curr_cont: = curr_cont.h_next; end;//I Draw the found greatest circuit img_res: = cvCreateImage (cvGetSize (img), IPL_DEPTH_8U, 1); cvDrawContours (img_res, bigest_contur, CV_RGB (255, 0, 255), CV_RGB (255, 0, 255), 1, CV_FILLED, 8, cvPoint (0, 0));//I Take out to a window cvNamedWindow (' original ', CV_WINDOW_AUTOSIZE); cvShowImage (' original ', img_res); cvWaitKey (); end. Instead of displaying the main circuit of the document, on the screen the main circuit of the document + a heap of small circuits around from a background is deduced. How further to cut off all but the greatest object and to turn this object on the necessary amount of degrees that its position became horizontal I have no concept. Can be eat those who worked with OpenCV and can help? Here the picture which turned out as a result: https://cloud.mail.ru/public/DNyj/MgJXm5R1n