ShivaGupta Posted December 30, 2013 Share Posted December 30, 2013 want to detect or cut text box in this image.........plz hep me 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 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. 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 On 12/30/2013 at 11:19 PM, jcbones said: 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 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 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. 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 On 12/31/2013 at 8:16 AM, Barand said: 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? 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 On 1/4/2014 at 1:04 PM, ShivaGupta said: 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 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...
Barand Posted January 4, 2014 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; } ?> 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 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 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 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 On 1/7/2014 at 5:28 PM, Barand said: I am not sure what you mean cut that detected part n save as this picture 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); 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 On 12/31/2013 at 8:16 AM, Barand said: 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 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 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 On 1/7/2014 at 7:46 PM, Barand said: GetFreaky See code in #8 above Completely missed it, thanks. Sorry for going off-topic a little there. 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..... 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.phpFetching info... 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
Archived
This topic is now archived and is closed to further replies.