Esempio n. 1
0
function bgidtocss($zoom = 1, $fid, $pid)
{
    global $db;
    $sql = "SELECT MIN(b.tlx) as tlx,MIN(b.tly) as tly,MAX(b.brx) as brx,MAX(b.bry) as bry, b.pid as pid, bg.btid as btid, b.bgid as bgid\r\n\t\tFROM boxes as b, boxgroupstype as bg\r\n\t\tWHERE b.pid = '{$pid}'\r\n\t\tAND bg.bgid = b.bgid\r\n\t\tAND bg.btid > 0\r\n\t\tAND bg.btid != 5\r\n\t\tGROUP BY bg.bgid\r\n\t\tORDER BY bg.sortorder ASC";
    $boxgroups = $db->GetAll($sql);
    $sql = "SELECT offx,offy,centroidx,centroidy,costheta,sintheta,scalex,scaley,width,height\r\n\t\tFROM formpages as f\r\n\t\tWHERE f.pid = {$pid} and f.fid = {$fid}";
    $row = $db->GetRow($sql);
    $sql = "SELECT b.bid\r\n\t\tFROM boxes as b, boxgroupstype as bg\r\n\t\tWHERE b.pid = '{$pid}'\r\n\t\tAND bg.bgid = b.bgid\r\n\t\tAND bg.btid > 0\r\n\t\tAND bg.btid != 5\r\n\t\tORDER BY bg.sortorder ASC, b.bid ASC";
    $boxes = $db->GetAll($sql);
    $vis = "visible";
    if (!isset($row['offx']) && !isset($row['offy'])) {
        $row = array();
        $row['offx'] = 0;
        $row['offy'] = 0;
        $row['centroidx'] = PAGE_WIDTH / 2;
        $row['centroidy'] = PAGE_HEIGHT / 2;
        $row['costheta'] = 1;
        $row['sintheta'] = 0;
        $row['scalex'] = 1;
        $row['scaley'] = 1;
    }
    //fix for upgrades
    if ($row['width'] == 0) {
        $row['width'] = PAGE_WIDTH;
    }
    if ($row['height'] == 0) {
        $row['height'] = PAGE_HEIGHT;
    }
    print "<form method=\"post\" action=\"{$_SERVER['PHP_SELF']}\">";
    foreach ($boxgroups as $boxgroup) {
        $crop = applytransforms($boxgroup, $row);
        $bgid = $boxgroup['bgid'];
        //make box group display higher
        $ttop = $crop['tly'] / $zoom - DISPLAY_GAP;
        if ($ttop < 0) {
            $ttop = 0;
        }
        print "<div id=\"boxGroup_{$bgid}\" style=\"position:absolute; top:" . $ttop . "px; width:1px; height:1px; background-color: " . BOX_BACKGROUND_COLOUR . ";opacity:.0;\"></div>";
        print "<div id=\"boxGroupBox_{$bgid}\" onclick=\"groupChange('{$bgid}');\" style=\"position:absolute; top:" . $crop['tly'] / $zoom . "px; left:" . $crop['tlx'] / $zoom . "px; width:" . ($crop['brx'] - $crop['tlx']) / $zoom . "px; height:" . ($crop['bry'] - $crop['tly']) / $zoom . "px; background-color: " . BOX_GROUP_BACKGROUND_COLOUR . ";opacity:" . BOX_GROUP_BACKGROUND_OPACITY . "; visibility: {$vis};\"></div>";
        print "<div><input type=\"checkbox\" name=\"bgid{$bgid}\" id=\"bgid{$bgid}\" style=\"opacity:0.0; \"/></div>";
        $vis = "hidden";
    }
    foreach ($boxes as $bi) {
        $bid = $bi['bid'];
        //if (!isset($_SESSION['boxes'][$bid])) break;
        $box = $_SESSION['boxes'][$bid];
        $val = $_SESSION['boxes'][$bid]['val'];
        $bbgid = $_SESSION['boxes'][$bid]['bgid'];
        $btid = $_SESSION['boxes'][$bid]['btid'];
        $box = applytransforms($box, $row);
        if ($btid == 1) {
            if ($val == 0) {
                $checked = "";
                $colour = BOX_BACKGROUND_COLOUR;
            } else {
                $checked = "checked=\"checked\"";
                $colour = BOX_SELECT_COLOUR;
            }
            print "<div><input type=\"checkbox\" name=\"bid{$bid}\" id=\"checkBox{$bid}\" value=\"{$bid}\" style=\"position:absolute; top:" . $box['tly'] / $zoom . "px; left:" . $box['tlx'] / $zoom . "px; width:" . ($box['brx'] - $box['tlx']) / $zoom . "px; height:" . ($box['bry'] - $box['tly']) / $zoom . "px; opacity:0.0; \" onclick=\"radioUpdate('{$bid}','{$bbgid}'); \" {$checked} onkeypress=\"checkEnter(event,{$bbgid},{$bid})\"/></div>";
            print "<div id=\"checkImage{$bid}\" onkeypress=\"checkEnter(event,{$bbgid},{$bid})\" onclick=\"radioChange('{$bid}','{$bbgid}'); \" style=\"position:absolute; top:" . $box['tly'] / $zoom . "px; left:" . $box['tlx'] / $zoom . "px; width:" . ($box['brx'] - $box['tlx']) / $zoom . "px; height:" . ($box['bry'] - $box['tly']) / $zoom . "px; background-color: {$colour};opacity:" . BOX_OPACITY . "; \"></div>";
        } else {
            if ($btid == 2) {
                if ($val == 0) {
                    $checked = "";
                    $colour = BOX_BACKGROUND_COLOUR;
                } else {
                    $checked = "checked=\"checked\"";
                    $colour = BOX_SELECT_COLOUR;
                }
                print "<div><input type=\"checkbox\" name=\"bid{$bid}\" id=\"checkBox{$bid}\" value=\"{$bid}\" style=\"position:absolute; top:" . $box['tly'] / $zoom . "px; left:" . $box['tlx'] / $zoom . "px; width:" . ($box['brx'] - $box['tlx']) / $zoom . "px; height:" . ($box['bry'] - $box['tly']) / $zoom . "px; opacity:0.0; \" onclick=\"checkUpdate('{$bid}','{$bbgid}'); \" {$checked} onkeypress=\"checkEnter(event,{$bbgid},{$bid})\" /></div>";
                print "<div id=\"checkImage{$bid}\" onkeypress=\"checkEnter(event,{$bbgid},{$bid})\" onclick=\"checkChange('{$bid}','{$bbgid}'); \" style=\"position:absolute; top:" . $box['tly'] / $zoom . "px; left:" . $box['tlx'] / $zoom . "px; width:" . ($box['brx'] - $box['tlx']) / $zoom . "px; height:" . ($box['bry'] - $box['tly']) / $zoom . "px; background-color: {$colour};opacity:" . BOX_OPACITY . ";  \"></div>";
            } else {
                if ($btid == 3 || $btid == 4) {
                    $maxlength = "maxlength=\"1\"";
                    $onkeypress = "onkeypress=\"textPress(this,event,{$bbgid},{$bid})\"";
                    if ($btid == 4) {
                        if (!is_numeric($val)) {
                            $val = "";
                        }
                    }
                    $val = htmlspecialchars($val);
                    print "<div><input type=\"text\" name=\"bid{$bid}\" id=\"textBox{$bid}\" value=\"{$val}\" {$maxlength} style=\"z-index: 1; position:absolute; top:" . ($box['tly'] / $zoom + ($box['bry'] - $box['tly']) / $zoom) . "px; left:" . $box['tlx'] / $zoom . "px; width:" . ($box['brx'] - $box['tlx']) / $zoom . "px; height:" . ($box['bry'] - $box['tly']) / $zoom . "px;\" onclick=\"\" onfocus=\"select()\" {$onkeypress} /></div>";
                    print "<div id=\"textImage{$bid}\" style=\"position:absolute; top:" . $box['tly'] / $zoom . "px; left:" . $box['tlx'] / $zoom . "px; width:" . ($box['brx'] - $box['tlx']) / $zoom . "px; height:" . ($box['bry'] - $box['tly']) / $zoom . "px; background-color: " . BOX_BACKGROUND_COLOUR . "; text-align:center; font-weight:bold;\" onclick=\"textClick('{$bid}','{$bbgid}');\">{$val}</div>";
                } else {
                    if ($btid == 6) {
                        $val = htmlspecialchars($val);
                        print "<div><textarea name=\"bid{$bid}\" id=\"textBox{$bid}\" style=\"z-index: 1; position:absolute; top:" . ($box['tly'] / $zoom + ($box['bry'] - $box['tly']) / $zoom) . "px; left:" . $box['tlx'] / $zoom . "px; width:" . ($box['brx'] - $box['tlx']) / $zoom . "px; height:" . ($box['bry'] - $box['tly']) / $zoom . "px;\" onclick=\"\" onfocus=\"select()\" rows=\"20\" cols=\"80\">{$val}</textarea></div>";
                        print "<div id=\"textImage{$bid}\" style=\"position:absolute; top:" . $box['tly'] / $zoom . "px; left:" . $box['tlx'] / $zoom . "px; width:" . ($box['brx'] - $box['tlx']) / $zoom . "px; height:" . ($box['bry'] - $box['tly']) / $zoom . "px; background-color: " . BOX_BACKGROUND_COLOUR . "; text-align:center; font-weight:bold;\" onclick=\"textClick('{$bid}','{$bbgid}');\">{$val}</div>";
                    }
                }
            }
        }
    }
    print "<div><input type=\"hidden\" name=\"piddone\" value=\"{$pid}\"/></div>";
    print "</form>";
}
Esempio n. 2
0
     //			if(isset($_GET['c'])){ imagepng($ttimage); die();}
     //			 imagepng($ttimage); die();
     //			image_to_text($ttimage);
     $kttimage = resize_bounding($ttimage);
     //			if(isset($_GET['d'])){ imagepng($kttimage); die();}
     //			 imagepng($kttimage); die();
     $i = thinzs_np($kttimage);
     imagepng($i);
     //imagepng(thin_b($timage));
     die;
     $box['tlx'] += BOX_EDGE;
     $box['tly'] += BOX_EDGE;
     $box['brx'] -= BOX_EDGE;
     $box['bry'] -= BOX_EDGE;
     header("Content-type: image/png");
     imagepng(crop($im, applytransforms($box, $row)));
 } else {
     if (isset($_GET['zoom'])) {
         header("Content-type: image/png");
         echo $row['image'];
     } else {
         $width = imagesx($im);
         $height = imagesy($im);
         $newwidth = DISPLAY_PAGE_WIDTH;
         $newheight = round($height * (DISPLAY_PAGE_WIDTH / $width));
         $thumb = imagecreatetruecolor($newwidth, $newheight);
         imagepalettecopy($thumb, $im);
         imagecopyresized($thumb, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
         header("Content-type: image/png");
         imagepng($thumb);
     }
Esempio n. 3
0
             $sql = "SELECT *\r\n\t\t\t\t\tFROM formpages\r\n\t\t\t\t\tWHERE pid = {$pid} and fid = {$fid}";
             $row = $db->GetRow($sql);
             if ($row['filename'] == '') {
                 $im = imagecreatefromstring($row['image']);
             } else {
                 $im = imagecreatefrompng(IMAGES_DIRECTORY . $row['filename']);
             }
         }
         $sql = "SELECT count(*) as c FROM ocrtrain\r\n\t\t\t\tWHERE fid = '{$fid}' and vid = '{$vid}' and bid = '{$bid}'";
         $cc = $db->GetRow($sql);
         if ($cc['c'] > 0) {
             print T_("Found duplicate") . " {$fid} {$vid} {$bid}";
         } else {
             $row['width'] = imagesx($im);
             $row['height'] = imagesy($im);
             $image = crop($im, applytransforms($box, $row));
             $a1 = kfill_modified($image, 5);
             $a2 = remove_boundary_noise($a1, 2);
             $timage = resize_bounding($a2);
             $bimage = thinzs_np($timage);
             $t = sector_distance($bimage);
             $count++;
             $sql = "INSERT INTO ocrtrain (ocrtid,val,f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16,fid,vid,bid,kb)\r\n\t\t\t\t\tVALUES (NULL,'{$val}','{$t[0][1]}','{$t[0][2]}','{$t[0][3]}','{$t[0][4]}','{$t[0][5]}','{$t[0][6]}','{$t[0][7]}','{$t[0][8]}','{$t[0][9]}','{$t[0][10]}','{$t[0][11]}','{$t[0][12]}','{$t[1][1]}','{$t[1][2]}','{$t[1][3]}','{$t[1][4]}','{$fid}','{$vid}','{$bid}','{$kb}')";
             $db->Execute($sql);
         }
     }
 }
 print T_("Trained") . ": {$count} " . T_("characters");
 //generate kb
 generate_kb($kb);
 print T_("Generated KB");
Esempio n. 4
0
function fillboxes($pid, $image, $fid, $transforms)
{
    global $db;
    $boxes = $db->GetAll("\tSELECT b.bid,b.tlx,b.tly,b.brx,b.bry,b.pid \r\n\t\t\t\tFROM boxes as b\r\n\t\t\t\tJOIN boxgroupstype AS bg on (bg.bgid = b.bgid AND (bg.btid = 1 or bg.btid = 2 or bg.btid = 3 or bg.btid = 4))\r\n\t\t\t\tWHERE b.pid = '{$pid}'");
    foreach ($boxes as $i) {
        $fill = fillratio($image, applytransforms($i, $transforms));
        //print "{$i['bid']} - $fill<br/>";
        boxfilled($i['bid'], $fid, $fill);
    }
}