Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
I'm trying to search for one image in another. I wrote a script but it doesn't work!
Old 03-09-2010, 08:44 PM I'm trying to search for one image in another. I wrote a script but it doesn't work!
Novice Talker

Posts: 8
Trades: 0
For example, I might have an image here:


And I might be looking for the smaller image:


within that bigger image. I want to get the x,y coordinates to where that image is in the large one. Here's the source code I have to do this:

PHP Code:
<?php
//small image
$im2 ImageCreateFromPNG("SMALL IMAGE.png");
$width imagesx($im2);
$height imagesy($im2);
$size2 $width $height;
$cw 0;
$ch 0;
$image2 "|";
for(
$i 0$i $size2$i++)
{
    
$image2 .= imagecolorat($im2$cw$ch)."|";
    if(
$cw == ($width 1))
    {
        
$cw 0;
        
$ch++;
    }else{
        
$cw++;
    }
}



//large image
$im ImageCreateFromPNG("BIG IMAGE.png");
$width imagesx($im);
$height imagesy($im);
$size2 $width $height;
$cw 0;
$ch 0;
$image "";

for(
$i 0$i $size2$i++)
{
    
$image .= imagecolorat($im$cw$ch)."|";
    if(
$cw == ($width 1))
    {
        
$cw 0;
        
$ch++;
    }else{
        
$cw++;
    }
}


//finding position of patch in strings
$find explode($image2,$image);
$coordinate substr_count($find[0], '|');


//converting position from string to x y coordinates
$width imagesx($im);
$check $coordinate $width;
$check explode(".",$check);
$y $check[0] + 1;
$x $coordinate $width;
if((
$coordinate $width) == 0)
{
    
$x $width;
    
$y--;
}


//printing result
echo "x: {$x}<br>y: {$y}";




?>
I tested each individual component of that manually and they all worked, but when put together it doesn't find the proper coordinates, just bogus ones. If someone could shed some light on this I would really appreciate it

Thank you,
Dave Z
macmee is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Reply     « Reply to I'm trying to search for one image in another. I wrote a script but it doesn't work!
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.13734 seconds with 12 queries