Working with MVG without saving

PerlMagick is an object-oriented Perl interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning PerlMagick.
Post Reply
L1800Turbo
Posts: 2
Joined: 2019-11-12T04:33:52-07:00
Authentication code: 1152

Working with MVG without saving

Post by L1800Turbo » 2019-11-12T04:52:41-07:00

Hello,

I'm converting an image to detect hough lines and plan to cut the image by these lines later on.

This works so far quite well:

Code: Select all

$x = $image->Read('10.tif');
warn "$x" if "$x";

my $houghImage = $image->Clone();

$x = $houghImage->CannyEdge('0x1+1%+1%');
warn "$x" if "$x";

$x = $houghImage->HoughLine('10x1000+800');
warn "$x" if "$x";

$x = $houghImage->Write('dings.mvg');
This produces a text file containing the coordinates.
However, my plan is to continue without saving the file and just using the data directly from $houghImage. I didn't find any way to extract these information as text (blob looked right so far, but I just got empty arrays). Current workaround is to save the file as mvg, reread it as text file and do RegExp search on the items.
I'm pretty shure, theres a better way...

I'm using ImageMagick 6.9.10-14 Q16 x86_64 20181023

Thanks!

snibgo
Posts: 12432
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Working with MVG without saving

Post by snibgo » 2019-11-12T05:17:15-07:00

L1800Turbo wrote:(blob looked right so far, but I just got empty arrays).
Did you follow the code used in coders\mvg.c WriteMVGImage()?
snibgo's IM pages: im.snibgo.com

L1800Turbo
Posts: 2
Joined: 2019-11-12T04:33:52-07:00
Authentication code: 1152

Re: Working with MVG without saving

Post by L1800Turbo » 2019-11-12T06:00:25-07:00

Didn't check it out so far, but I saw following command:

Code: Select all

value=GetImageArtifact(image,"mvg:vector-graphics");
equivalent in Perl was

Code: Select all

$x = $houghImage->Set('magick'=>'mvg:vector-graphics');
Now

Code: Select all

my @blobs = $houghImage->ImageToBlob();
provides the content on $blob[0].

Thank you! :)

My current prototype. Propably primitive, but working, at least on my test file..

Code: Select all

#!/usr/bin/perl -w
use strict;
use warnings;
use Scalar::Util 'looks_like_number';

use Image::Magick;

my $x;
my $i = 0;
my $xOld = 0;

my $image = Image::Magick->new;

my $regFl = "[0-9]{1,4}.{0,1}[0-9]*";

my @fileNames = ('10.tif');
$x = $image->Read(@fileNames);
warn "$x" if "$x";

my $houghImage = $image->Clone();

$x = $houghImage->CannyEdge('0x1+1%+1%');
warn "$x" if "$x";

$x = $houghImage->HoughLine('10x1000+800');
warn "$x" if "$x";

$x = $houghImage->Set('magick'=>'mvg:vector-graphics');
warn "$x" if "$x";

#$x = $houghImage->Write('dings.mvg');

my @blobs = $houghImage->ImageToBlob();
warn "$x" if "$x";

# print $blobs[0];


while($blobs[0] =~ m/line ($regFl),$regFl $regFl,($regFl)/g)
{
    if($xOld > 0)
    {
        my $imageCurrent = $image->Clone();
        print("deltaX: ".($1-$xOld).", xOld: $xOld\n");
        
        $x = $imageCurrent->Crop(geometry=>($1-$xOld).'x'.$2.'+'.$xOld.'+0');
        warn "$x" if "$x";

        $x = $imageCurrent->Write('output/cut'.$i.'.tif');
        warn "$x" if "$x";
        
        $i++;
    }
    $xOld = $1;
}

Post Reply