Example #1
0
function createboxes($sx, $sy, $x, $y, $pid, $qid)
{
    //done now calculate map
    include "../functions/functions.boxdetection.php";
    include "../functions/functions.image.php";
    include "../functions/functions.barcode.php";
    global $db;
    //first see if boxes exist within this selection - if so merge them in to one
    //box group
    //
    $sql = "SELECT count(DISTINCT bgid)\r\n          FROM boxes\r\n          WHERE pid = '{$pid}'\r\n          AND tlx > '{$sx}' AND brx > '{$sx}'\r\n          AND tly > '{$sy}' AND bry > '{$sy}'\r\n          AND tlx < '{$x}' AND brx < '{$x}' \r\n          AND tly < '{$y}' AND bry < '{$y}'";
    $groups = $db->GetOne($sql);
    if ($groups == 0) {
        //no existing boxes in this selection so create a new box group
        $sql = "SELECT image \r\n      FROM pages\r\n      WHERE pid = {$pid}";
        $row = $db->GetRow($sql);
        if (empty($row)) {
            exit;
        }
        $image = imagecreatefromstring($row['image']);
        $barcode = crop($image, array("tlx" => $sx, "tly" => $sy, "brx" => $x, "bry" => $y));
        //check for barcode
        $barcodenum = barcode($barcode, 1, false, true);
        if ($barcodenum) {
            $a = array();
            $a[] = array($sx);
            $a[] = array($sy);
            $a[] = array($x);
            $a[] = array($y);
            $barcodewidth = strlen($barcodenum);
        } else {
            $lw = lineWidth($sx, $sy, $x, $y, $image);
            $a = 0;
            //print_r($lw);
            $a = vasBoxDetection($lw);
            if ($a == false) {
                if ($x - $sx > $y - $sy) {
                    $a = horiBoxDetection($lw);
                } else {
                    $a = vertBoxDetection($lw);
                }
            }
        }
        //convert to box format
        $boxes = array();
        for ($i = 0; $i < count($a[0]); $i++) {
            $box = array();
            $box['tlx'] = $a[0][$i];
            $box['tly'] = $a[1][$i];
            $box['brx'] = $a[2][$i];
            $box['bry'] = $a[3][$i];
            $boxes[] = $box;
        }
        $crop = array();
        $crop['tlx'] = $sx;
        $crop['tly'] = $sy;
        $crop['brx'] = $x;
        $crop['bry'] = $y;
        if ($barcodenum) {
            //create barcode box group
            $bgid = createboxgroup($boxes, $barcodewidth, 'tmpbarcode', $pid, 5);
        } else {
            if (count($boxes) > 0) {
                //create single choice box group by default
                $bgid = createboxgroup($boxes, 1, 'tmp', $pid, 1);
            } else {
                //nothing detected -  create a text box
                $bgid = createboxgroup(array($crop), 1, 'tmpbox', $pid, 6);
            }
        }
    } else {
        if ($groups > 1) {
            //existing boxes in this selection that are part of more than one box group
            $db->StartTrans();
            //make them all part of the first box group
            $sql = "SELECT bgid\r\n          FROM boxes\r\n          WHERE pid = '{$pid}'\r\n          AND tlx > '{$sx}' AND brx > '{$sx}'\r\n          AND tly > '{$sy}' AND bry > '{$sy}'\r\n          AND tlx < '{$x}' AND brx < '{$x}' \r\n          AND tly < '{$y}' AND bry < '{$y}'";
            $group = $db->GetOne($sql);
            $sql = "SELECT DISTINCT bgid\r\n          FROM boxes\r\n          WHERE pid = '{$pid}'\r\n          AND tlx > '{$sx}' AND brx > '{$sx}'\r\n          AND tly > '{$sy}' AND bry > '{$sy}'\r\n          AND tlx < '{$x}' AND brx < '{$x}' \r\n          AND tly < '{$y}' AND bry < '{$y}'\r\n         AND bgid != '{$group}'";
            $rs = $db->GetAll($sql);
            foreach ($rs as $r) {
                $sql = "DELETE FROM boxgroupstype WHERE bgid = {$r['bgid']}";
                $db->Execute($sql);
            }
            $sql = "UPDATE boxes\r\n            SET bgid = '{$group}'\r\n            WHERE pid = '{$pid}'\r\n            AND tlx > '{$sx}' AND brx > '{$sx}'\r\n            AND tly > '{$sy}' AND bry > '{$sy}'\r\n            AND tlx < '{$x}' AND brx < '{$x}' \r\n            AND tly < '{$y}' AND bry < '{$y}'";
            $db->Execute($sql);
            $db->CompleteTrans();
        }
    }
}
Example #2
0
 $image = imagecreatefromstring($row['image']);
 $barcode = crop($image, array("tlx" => $sx, "tly" => $sy, "brx" => $x, "bry" => $y));
 //check for barcode
 $barcodenum = barcode($barcode);
 if ($barcodenum) {
     $a = array();
     $a[] = array($sx);
     $a[] = array($sy);
     $a[] = array($x);
     $a[] = array($y);
     $barcodewidth = strlen($barcodenum);
 } else {
     $lw = lineWidth($sx, $sy, $x, $y, $image);
     $a = 0;
     //print_r($lw);
     $a = vasBoxDetection($lw);
     if ($a == false) {
         if ($x - $sx > $y - $sy) {
             $a = horiBoxDetection($lw);
         } else {
             $a = vertBoxDetection($lw);
         }
     }
 }
 $boxes = count($a[0]);
 //convert to box format
 $boxes = array();
 for ($i = 0; $i < count($a[0]); $i++) {
     $box = array();
     $box['tlx'] = $a[0][$i];
     $box['tly'] = $a[1][$i];
Example #3
0
function createboxes($sx, $sy, $x, $y, $pid, $qid)
{
    //done now calculate map
    include "../functions/functions.boxdetection.php";
    include "../functions/functions.image.php";
    include "../functions/functions.barcode.php";
    global $db;
    $sql = "SELECT image \n\t\tFROM pages\n\t\tWHERE pid = {$pid}";
    $row = $db->GetRow($sql);
    if (empty($row)) {
        exit;
    }
    $image = imagecreatefromstring($row['image']);
    $barcode = crop($image, array("tlx" => $sx, "tly" => $sy, "brx" => $x, "bry" => $y));
    //check for barcode
    $barcodenum = barcode($barcode);
    if ($barcodenum) {
        $a = array();
        $a[] = array($sx);
        $a[] = array($sy);
        $a[] = array($x);
        $a[] = array($y);
        $barcodewidth = strlen($barcodenum);
    } else {
        $lw = lineWidth($sx, $sy, $x, $y, $image);
        $a = 0;
        //print_r($lw);
        $a = vasBoxDetection($lw);
        if ($a == false) {
            if ($x - $sx > $y - $sy) {
                $a = horiBoxDetection($lw);
            } else {
                $a = vertBoxDetection($lw);
            }
        }
    }
    $boxes = count($a[0]);
    //convert to box format
    $boxes = array();
    for ($i = 0; $i < count($a[0]); $i++) {
        $box = array();
        $box['tlx'] = $a[0][$i];
        $box['tly'] = $a[1][$i];
        $box['brx'] = $a[2][$i];
        $box['bry'] = $a[3][$i];
        $boxes[] = $box;
    }
    $crop = array();
    $crop['tlx'] = $sx;
    $crop['tly'] = $sy;
    $crop['brx'] = $x;
    $crop['bry'] = $y;
    if ($barcodenum) {
        //create barcode box group
        $bgid = createboxgroup($boxes, $barcodewidth, 'tmpbarcode', $pid, 5);
    } else {
        //create single choice box group by default
        $bgid = createboxgroup($boxes, 1, 'tmp', $pid, 1);
    }
}