Dear monks:
I planning to do some product researches in my little clothing store. My problem is that the products in my store all have no barcodes on them. I cannot use barcodes to keep record on each item I sold. I have more than couple thousands items in the store; every day we will renew hundrads sold items, print individual barcodes become a hard job and needs training.
My solution to the problem, I don't need barcodes, I just take a photo for each item when it is sold. Then I can apply AI technics to recognize and classify the photos. Then I would be able to know, say, how many pants, tops or skirts I sold each day.
I developed a technic to calculate some indicator values of each photo. I tested it on photos from only three types of items. It worked quite good. However there are less than a hundred types item in the store, and many of them are very similar on colors, I consider the technic will not be powerful enough. I have some codes after you guys reading this; it was modified from a monk merlyns code.
Can anyone of you have specific image recognition knowledges to introduce me a professional way to do this? By the way, I thought I can use perl to control the PC camera to make taking photo easy. Fanally I figured out that's impossible under at least windows OS. So just processing photos, can we do it?
#!/usr/bin/perl #by monk zli034 use strict; use Image::Magick; use Cache::FileCache; my @files = (); my $folder = "c:\\photos"; my $FUZZ = 5; # permitted average deviation in the vector elements my $CORRUPT = "CORRUPT"; # if defined, rename corrupt images into this + dir my $cache = Cache::FileCache->new; unless (opendir(FOLDER, $folder)){ print "Cannot opne folder $folder!\n"; exit; } @files = grep (!/^\.\.?$/, readdir(FOLDER)); closedir(FOLDER); #print join("\n", @files), "\n"; sub warnif; my $write="ID,mean,stdv,class\n"; foreach my $file (@files){ #the first number of the photo file gives the #information of the type of the item. my $class; if ($file =~ /^1/){ $class = "first";} if ($file =~ /^2/){ $class = "second";} if ($file =~ /^3/){ $class = "third";} #print $file; my $image = Image::Magick->new; my $x = $image->Read($folder."\\".$file); #print $file; my @vector; #print "... skipping ($file)\n"; #print "\n"; my (@stat) = stat(_) or die "should not happen: $!"; # retur +n 13 elements of file status. my $key = "@stat[0, 1, 9]"; # dev/ino/mtime print "$file is ", join("x",$image->Get('width', 'height')), + "\n"; warnif $image->Normalize(); warnif $image->Resize(geometry => '4x4!'); warnif $image->Set(magick => 'rgb'); @vector = unpack "C*", $image->ImageToBlob(); print "vector ", @vector, "\n"; $cache->set($key, [@vector]); my $mean = mean(@vector); my $stdv = std_dev($mean, @vector); print "mean $mean \n"; print "standard deviation $stdv \n"; #$write=$write.$file.",".$mean.",".$stdv.",".$class."\n"; foreach my $element (@vector){ $write=$write.$element.","; } $write = $write.$class."\n"; } #Output result-------------------------------------------------- open(OUTFILE, ">testdata.csv") or die "Can't open testdata.csv: $!"; print OUTFILE $write; close OUTFILE; use Carp qw(carp); sub warnif { my $value = shift; carp $value if $value; } sub mean { my $result; foreach (@_) { $result += $_ } return $result / @_; } sub std_dev { my ($mean, @vector) = @_; my @elem_squared; foreach my $element(@vector) { push (@elem_squared, ($element **2)); } return sqrt( mean(@elem_squared) - ($mean ** 2)); }
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |