ShivaGupta Posted December 30, 2013 Share Posted December 30, 2013 (edited) want to detect or cut text box in this image.........plz hep me Edited December 30, 2013 by ShivaGupta Quote Link to comment https://forums.phpfreaks.com/topic/284988-how-to-detect-text-box-in-an-image/ Share on other sites More sharing options...
Firemankurt Posted December 30, 2013 Share Posted December 30, 2013 Not much experience in this area but I have used "imagemagick" with PHP and I did find a possible lead for you: Searching Google for "php imagemagick ocr" Found: http://stackoverflow.com/questions/11978986/ocr-getting-text-from-image-using-tesseract-3-0-and-imagemagick-6-6-5 Quote Link to comment https://forums.phpfreaks.com/topic/284988-how-to-detect-text-box-in-an-image/#findComment-1463353 Share on other sites More sharing options...
jcbones Posted December 30, 2013 Share Posted December 30, 2013 This is why Captcha's are getting harder for users to see. No help from me. Quote Link to comment https://forums.phpfreaks.com/topic/284988-how-to-detect-text-box-in-an-image/#findComment-1463361 Share on other sites More sharing options...
ShivaGupta Posted December 31, 2013 Author Share Posted December 31, 2013 (edited) This is why Captcha's are getting harder for users to see. No help from me. its not a captcha n i want only Get The Text Box Position in image not text....so plz help Edited December 31, 2013 by ShivaGupta Quote Link to comment https://forums.phpfreaks.com/topic/284988-how-to-detect-text-box-in-an-image/#findComment-1463403 Share on other sites More sharing options...
Barand Posted December 31, 2013 Share Posted December 31, 2013 (edited) Start at the top left and look for an occurrence of many contiguous horizontal white pixels. Then work back from bottom right looking for same. Edited December 31, 2013 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/284988-how-to-detect-text-box-in-an-image/#findComment-1463406 Share on other sites More sharing options...
ShivaGupta Posted January 4, 2014 Author Share Posted January 4, 2014 Start at the top left and look for an occurrence of many contiguous horizontal white pixels. Then work back from bottom right looking for same. is their any example? Quote Link to comment https://forums.phpfreaks.com/topic/284988-how-to-detect-text-box-in-an-image/#findComment-1463821 Share on other sites More sharing options...
Barand Posted January 4, 2014 Share Posted January 4, 2014 is their any example? Not that I know of, you may have to roll up your sleeves and dive in. It should just require a couple of nested for() loops and use of imagecolorat to test each pixel Quote Link to comment https://forums.phpfreaks.com/topic/284988-how-to-detect-text-box-in-an-image/#findComment-1463828 Share on other sites More sharing options...
Solution Barand Posted January 4, 2014 Solution Share Posted January 4, 2014 I tried it with the png image you posted. It fount the top left OK but when working up from the bottom of the image it couldn't find a long chain of white pixels until it reached row 7 (should have found one at row 47). The only thing I can think of is there may be some anti-aliasing and not all pixels in the text background are a perfect white. I saved the image as a a gif file to reduce the color resolution and it worked fine giving left top (20, 0) right bottom (462, 47) gif image attached Here's the code <?php $im = imagecreatefromgif('shiva1.gif'); $iw = imagesx($im); $ih = imagesy($im); $wht = imagecolorresolve($im,0xFF,0xFF,0xFF); $top = $left = $bottom = $right = -1; /*************************************** * search from top left * ****************************************/ for ($y=0; $y<$ih; $y++) { for ($x=0; $x<$iw; $x++) { if (countRight($im, $x, $y, $iw, $wht) >= 100) { $top = $y; $left = $x; break 2; } } } echo "left top ($left, $top)<br>"; /*************************************** * search from bottom right * ****************************************/ for ($y=$ih-1; $y>0; $y--) { for ($x=$iw-1; $x>0; $x--) { if (countLeft($im, $x, $y, $wht) >= 100) { $bottom = $y; $right = $x; break 2; } } } echo "right bottom ($right, $bottom)"; /******************************************************* * functions to count horizontal white pixels * ********************************************************/ function countRight($im, $x, $y, $iw, $wht) { $k = 0; while ($x < $iw) { if (imagecolorat($im, $x, $y)!=$wht) { return $k; } ++$k; ++$x; } return $k; } function countLeft($im, $x, $y, $wht) { $k = 0; while ($x > 0) { if (imagecolorat($im, $x, $y)!=$wht) { return $k; } ++$k; --$x; } return $k; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/284988-how-to-detect-text-box-in-an-image/#findComment-1463879 Share on other sites More sharing options...
ShivaGupta Posted January 7, 2014 Author Share Posted January 7, 2014 (edited) ok sir Thanks a lot .... and again here i want to save new picture with detected pixeles left top (20, 0)right bottom (462, 47) i tried myself but i am new in php so no luck plz help again.........Thank you Edited January 7, 2014 by ShivaGupta Quote Link to comment https://forums.phpfreaks.com/topic/284988-how-to-detect-text-box-in-an-image/#findComment-1464272 Share on other sites More sharing options...
Barand Posted January 7, 2014 Share Posted January 7, 2014 I am not sure what you mean Quote Link to comment https://forums.phpfreaks.com/topic/284988-how-to-detect-text-box-in-an-image/#findComment-1464275 Share on other sites More sharing options...
ShivaGupta Posted January 7, 2014 Author Share Posted January 7, 2014 (edited) I am not sure what you mean cut that detected part n save as this picture Edited January 7, 2014 by ShivaGupta Quote Link to comment https://forums.phpfreaks.com/topic/284988-how-to-detect-text-box-in-an-image/#findComment-1464276 Share on other sites More sharing options...
Barand Posted January 7, 2014 Share Posted January 7, 2014 Delete the 2 lines that echo the left-top and right-bottom coordinates then add this code /************************************************ * Create image of the text area * *************************************************/ $im2 = imagecreate($right-$left, $bottom-$top); imagecopy($im2, $im, 0, 0, $left, $top, $right-$left, $bottom-$top); // output image header("Content-type: image/gif"); imagegif($im2); imagedestroy($im); imagedestroy($im2); Quote Link to comment https://forums.phpfreaks.com/topic/284988-how-to-detect-text-box-in-an-image/#findComment-1464290 Share on other sites More sharing options...
GetFreaky Posted January 7, 2014 Share Posted January 7, 2014 (edited) Start at the top left and look for an occurrence of many contiguous horizontal white pixels. Then work back from bottom right looking for same. Does PHP allow to iterate pixel by pixel... like this for example for($y=0;$y<=$height;$y++) { for($x=0;$x<=$width;$x++) { // pixel manipulation here } } Whenever I worked with images with php, it was always built-in functions, not sure how flexible the libraries actually are. From what I remember they had a layer of abstraction and you can invoke functions to do certain things to a group of pixels, don't know about pixel by pixel Edited January 7, 2014 by GetFreaky Quote Link to comment https://forums.phpfreaks.com/topic/284988-how-to-detect-text-box-in-an-image/#findComment-1464306 Share on other sites More sharing options...
Barand Posted January 7, 2014 Share Posted January 7, 2014 GetFreaky See code in #8 above Quote Link to comment https://forums.phpfreaks.com/topic/284988-how-to-detect-text-box-in-an-image/#findComment-1464311 Share on other sites More sharing options...
GetFreaky Posted January 7, 2014 Share Posted January 7, 2014 (edited) GetFreaky See code in #8 above Completely missed it, thanks. Sorry for going off-topic a little there. Edited January 7, 2014 by GetFreaky Quote Link to comment https://forums.phpfreaks.com/topic/284988-how-to-detect-text-box-in-an-image/#findComment-1464316 Share on other sites More sharing options...
ShivaGupta Posted January 7, 2014 Author Share Posted January 7, 2014 @ Barand Thanks A Lot Sir ...Code Working Fine..... Quote Link to comment https://forums.phpfreaks.com/topic/284988-how-to-detect-text-box-in-an-image/#findComment-1464344 Share on other sites More sharing options...
Barand Posted January 8, 2014 Share Posted January 8, 2014 I managed to get the correct result on the original PNG image by adjusting the image brightness (line 5 in code attached) textarea.php Quote Link to comment https://forums.phpfreaks.com/topic/284988-how-to-detect-text-box-in-an-image/#findComment-1464437 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.