imperium2335 Posted April 16, 2009 Share Posted April 16, 2009 This may be a bit far-out . Firstly not that hard I'd image, can PHP get the colour information of an image? Like return a value that could indicate that most of the image is e.g. black. Second, can it apply a 3d matrix over an image and rotate it so its like scanning the image, e.g if the picture has a big 30 made out of cheese on it, can php stick a 3d 30 over the image and spin it around, resize it etc etc until the 3d matrix has matched the shape of the 30 in the image (youd give it say 10 seconds to scan, if not matched in the time limit then move on to next image). With some margin of error of course (may not be a perfectly shaped 30) then have it do something when a match is found e.g. say “this picture has an item that looks like a 30”? Or is that way beyond todays php ? Quote Link to comment https://forums.phpfreaks.com/topic/154281-advanced-image-scan-with-php/ Share on other sites More sharing options...
.josh Posted April 16, 2009 Share Posted April 16, 2009 you can do a nested for loop to go pixel by pixel and populate an color=>count of all the different colors and then divide each count by total pixels * 100 to get the percentage of each color in the image. I'm quite sure I've seen plenty of scripts that already do this, if you don't wanna write that yourself. Not that this step is any kind of difficult...5-10 lines tops. create image source for loop for loop get pixel info $color[rgb]++; } } $totalpixels = array_sum($color); foreach ($color as $k => $v) { $color[$k] = $v / $totalpixels * 100; } As far as the whole scanning thing, there would be a big margin of error and unreliability, regardless of what you try to do. I personally would initially approach it by filtering the image down to only a couple of colors (think along the same lines of in paint/image editing programs, the "outline horizontile/vertical" feature, or the "emboss" feature) first. Ideally straight black and white. From there I would...try to come up with a way to find the boundaries of the shape. Maybe something involving overlaying the image with a grid and looping through x1,y1,x2,y2 cell coord for presence of pixels. As a first version, I would just compare it as if it were a solid shape. a "swiss cheese" 3 would ideally match less than a solid 3 for example, but figuring it out at that level of granularity would pretty much involve recursively repleating some of these steps. Quote Link to comment https://forums.phpfreaks.com/topic/154281-advanced-image-scan-with-php/#findComment-811119 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.