Main Menu

Unblessed reference error

Started by Archive, May 12, 2010, 08:53:54 AM

Previous topic - Next topic

Archive

[Originally posted by gregkeene on 2006-05-24 19:37:01-07]

In the code below, I get the error:

  Can't call method "SetNewValue" on unblessed reference at /Users/greg/bin/rawtest.pl line 13.

Any help is appreciated!

Greg
----
Code:
#!/usr/bin/perl -w

use Image::ExifTool 'ImageInfo';
#use IO::File;
#use Time::Local;

$photodirectory = "/Volumes/d\$/PhotoMaster/rawtest/";

opendir(DIRHANDLE, "$photodirectory") || die "Cannot opendir $photodirectory: $!";
foreach $file (sort readdir(DIRHANDLE)) {
   my $info = ImageInfo($photodirectory.$file);
   if (($file =~ /4892test.cr2/)|($file =~ /4892test.CR2/)) {
      $info->SetNewValue("Caption", "Gregs test");
      $info->WriteInfo($file);
      foreach (keys %$info) {
         if ($_ =~ /ObjectName/) {
            print "$_: $info->{$_}\n";
         }
      }

   }
}
closedir(DIRHANDLE);

exit;

Archive

[Originally posted by exiftool on 2006-05-25 11:46:33-07]

Hi Greg,

You need to call SetNewValue() with an instance of an ExifTool object.  ie)

Code:
#!/usr/bin/perl -w

use Image::ExifTool 'ImageInfo';
#use IO::File;
#use Time::Local;

my $exifTool = new Image::ExifTool;

$photodirectory = "/Volumes/d\$/PhotoMaster/rawtest/";

opendir(DIRHANDLE, "$photodirectory") || die "Cannot opendir $photodirectory: $!";
foreach $file (sort readdir(DIRHANDLE)) {
        my $info = $exifTool->ImageInfo($photodirectory.$file);
        if (($file =~ /4892test.cr2/)|($file =~ /4892test.CR2/)) {
                $exifTool->SetNewValue("ImageDescription", "Gregs test");
                $exifTool->WriteInfo($photodirectory.$file);
                foreach (keys %$info) {
                        if ($_ =~ /ObjectName/) {
                                print "$_: $info->{$_}\n";
                        }
                }

        }
}
closedir(DIRHANDLE);

exit;

The $info hash returned by ImageInfo() is not the same as an ExifTool object.  I hope this makes sense.

While I was making changes, I also called ImageInfo() with the $exifTool object I created.  Also, I have a few other comments about your script: 1) I have added the directory to the filename in the WriteInfo() call, otherwise this call won't find the file.  2) There is no writable "Caption" tag.  You want to either  write "ImageDescription" or "UserComment".  3) I'm not sure why you're looking for the "ObjectName" tag, but I don't think you'll find it. 4) The $info you're looking at will be before the new information you write.  If you want to read back the new information you wrote, call ImageInfo() after WriteInfo().

   - Phil

Archive

[Originally posted by gregkeene on 2006-05-25 15:22:38-07]

Phil:

We're getting close. But I'm still not able to set any values. I tried your code exactly from the post above and also changed the field to one I knew my camera had. So, to simplify the discussion, I've changed the code to this, still doesn't work:

-----------------------------------------------------------------------
Code:
#!/usr/bin/perl -w

use Image::ExifTool 'ImageInfo';
#use IO::File;
#use Time::Local;

my $exifTool = new Image::ExifTool;

$photodirectory = "/Volumes/d\$/PhotoMaster/rawtest/";
$file = "20060429-30D-IMG_4892test.CR2";

my $info = $exifTool->ImageInfo($photodirectory.$file);
$exifTool->SetNewValue("ImageDescription", "A499JKLLL");
$exifTool->WriteInfo($photodirectory.$file);

exit;

-----------------------------------------------------------------------

Also, using this code, here are the values I'm getting out of my files:
Code:
foreach (keys %$info) {
   print "$_: $info->{$_}\n";
}

-----------------------------------------------------------------------
Code:
WhiteBalance (1): Auto
FocalPlaneYSize: 15.37mm
BulbDuration: 0
TimeCreated: 12:38:24-08:00
FlashFiring: Fires
SensorHeight: 2360
ShootingMode: Shutter Speed Priority AE
CopyrightNotice: Copyright 2006 Greg Keene, All Rights Reserved.
SensorBlueLevel: 0
WB_RGGBLevelsFluorescent: 1853 1057 1057 2352
FNumber (1): 11
Source: SourceValue
BitsPerSample: 8 8 8
Rights: Copyright 2006 Greg Keene, All Rights Reserved.
ZoomTargetWidth: 0
MIMEType: image/x-raw
WB_RGGBLevelsPC1: 8191 1056 1056 512
MirrorLockup: Disable
LensType: EF100-400mm f/4.5-5.6L IS USM
Compression (1): JPEG (old-style)
FileType: CR2
Credit (1): CreditValue
FlashActivity: 0
MagnifiedView: Image playback only
ImageHeight: 1152
DateTimeOriginal: 2006:04:29 12:38:24
WB_RGGBLevelsKelvin: 2060 1024 1024 1535
FocusDistanceUpper: 0
ISO (1): 400
PhotoEffect: Off
ScaleFactor35efl: 1.6
ColorTempCloudy: 6000
Marked: True
By-lineTitle: TitleValue
ComponentsConfiguration:
WBShiftAB: 0
ColorTempMeasured: 5893
Saturation: Normal
BracketMode: Off
WhiteBalanceRed: 0
WB_RGGBLevelsAuto: 2189 1024 1024 1402
RedBalance: 2.137695
ModifyDate: 2006:04:29 12:38:24
CanonImageWidthAsShot: 3504
FocalLength: 400.0mm
ColorTempPC2: 3761
Credit: CreditValue
MeteringMode (1): Multi-segment
WhiteBalance: Auto
Urgency (1): 5
Lens: 100.0 - 400.0mm
SensorWidth: 3596
SafetyShiftInAvOrTv: Disable
ExposureTime: 1/250
HyperfocalDistance: 756.35 m
WB_RGGBLevelsShade: 2372 1024 1024 1268
CircleOfConfusion: 0.019 mm
FlashExposureComp: 0
ExposureTime (1): 1/256
Compression: JPEG (old-style)
CanonFlashMode: Off
ThumbnailLength: 8152
ShortFocal: 100
WBBracketValueAB: 0
ColorSpace (1): sRGB
Caption-Abstract: Coye Francies before the Spring game.

DigitalZoom: None
ObjectName: ObjectName
DateCreated (1): 2006:04:29
ExposureMode: Auto
CanonImageType: Canon EOS 30D
XResolution: 72
StripOffsets (1): 449776
SensorRightBorder: 3587
ColorTempAuto: 5893
ShutterCount: 2033254592
TimeCreated (1): 123824-0800
EasyMode: Manual
ETTLII: Evaluative
WB_RGGBLevelsPC2: 8191 1056 1056 512
UserComment:
FocusDistanceLower: 0
ExposureCompensation: 0
ColorSpace: sRGB
Title: ObjectName
FlashGuideNumber: 0
WB_RGGBLevels: 2189 1024 1024 1402
SequenceNumber: 0
LensAFStopButton: AF stop
WBBracketValueGM: 0
Sharpness: +3
CustomRendered: Normal
RawJpgQuality: Fine
ISOExpansion: On
ExposureLevelIncrements: 1/3 Stop
CanonExposureMode: Shutter Speed Priority AE
FocalPlaneXResolution: 3959.322
StripByteCounts: 7089343
SensorBottomBorder: 2354
ExifImageLength: 2336
ColorTempShade: 7000
StripByteCounts (1): 294912
DigitalGain: 0
FocusRange: Not Known
WB_RGGBLevelsDaylight: 2060 1024 1024 1535
BracketShotNumber: 0
SensorTopBorder: 19
ColorTone: Normal
FocalType: Zoom
AFAssistBeam: Emits
ApplicationRecordVersion: 3
Self-timer2: 0
ThumbnailOffset: 76800
ColorTempAsShot: 5893
LongExposureNoiseReduction: Off
FlashSyncSpeedAv: Auto
Model: Canon EOS 30D
FlashpixVersion: 0100
ShutterSpeed: 1/250
CanonModelID: EOS 30D
ResolutionUnit: inches
FocalLength35efl: 400.0mm (35mm equivalent: 625.0mm)
CanonImageHeightAsShot: 2336
MeteringMode: Evaluative
MaxAperture: 5.6
InteropVersion: 0100
WB_RGGBLevelsMeasured: 2187 1024 1023 1400
SamplesPerPixel: 3
WBBracketMode: Off
SerialNumber: 0420300677
WB_RGGBLevelsAsShot: 2189 1024 1024 1402
Source (1): SourceValue
ExifToolVersion: 6.15
DateTimeCreated: 2006:04:29 12:38:24-08:00
StripOffsets: 744688
ISO: 400
Directory: /Volumes/d$/PhotoMaster/rawtest
PlanarConfiguration: Chunky
Make: Canon
MacroMode: Normal
ImageDescription: Coye Francies before the Spring game.

InteropIndex: R98
LensType (1): Unknown (-1)
BlueBalance: 1.369141
ApertureValue: 11.0
ExposureCompensation (1): 0
PhotometricInterpretation: RGB
ExifImageWidth: 3504
MinAperture: 38
ExposureProgram: Shutter speed priority AE
SensorLeftBorder: 84
WB_RGGBLevelsFlash: 2250 1024 1024 1348
FocalUnits: 1
Compression (2): JPEG (old-style)
PreviewImageLength: 364824
ColorTemperature: 5200
FocalPlaneXSize: 23.04mm
Quality: RAW
DriveMode: Continuous shooting
WB_RGGBLevelsCloudy: 2222 1024 1024 1391
ColorTempKelvin: 5210
Lens35efl: 100.0 - 400.0mm (35mm equivalent: 156.2 - 625.0mm)
SuperimposedDisplay: On
FocusMode: AI Servo AF
AEBBracketValue: 0
Flash: Off
PreviewImage: SCALAR(0x186f924)
ShutterSpeedValue: 1/250
CanonImageSize: Unknown (-1)
PictureStyle: Standard
Orientation: Horizontal (normal)
FocalLength (1): 400mm
BracketValue: 0
WB_RGGBLevelsTungsten: 1537 1095 1095 2595
ExifVersion: 0221
ColorTempTungsten: 3200
ColorTempFluorescent: 3752
ImageSize: 1728x1152
ColorTempPC3: 3761
DateCreated: 2006:04:29
WB_RGGBLevelsCustom: 2060 1024 1024 1535
ThumbnailImage: SCALAR(0x19300b4)
FocusContinuous: Continuous
Contrast: Normal
SensorRedLevel: 0
SlowShutter: None
ImageWidth: 1728
CanonImageWidth: 3504
ColorTempDaylight: 5200
WB_RGGBLevelsPC3: 8191 1056 1056 512
Keywords: OSU, Beavers, Spring Practice, Football, Spring, OSU Beavers, Oregon State University, BeaverPigSkin, 2006, BeaversSpring20060429, Game, Spring Game, Coye Francies
ImageHeight (1): 256
PreviewImageStart: 84952
ToneCurve: Standard
ImageWidth (1): 384
ZoomSourceWidth: 0
SharpnessFrequency: n/a
ColorTempCustom: 5210
ContinuousDrive: Continuous, Low
SerialNumberFormat: Format 2
ColorTempFlash: 6290
RowsPerStrip: 256
Subject: OSU, Beavers, Spring Practice, Football, Spring, OSU Beavers, Oregon State University, BeaverPigSkin, 2006, BeaversSpring20060429, Game, Spring Game, Coye Francies
WhiteBalanceBlue: 0
FocalPlaneYResolution: 3959.322
BitsPerSample (1): 8 8 8
FileName: 20060429-30D-IMG_4892test.CR2
FlashBits: (none)
AEBSequence: 0,-,+/Enabled
AFPointSelectionMethod: Normal
TargetAperture: 11
TargetExposureTime: 1/256
CreateDate: 2006:04:29 12:38:24
WBShiftGM: 0
AddOriginalDecisionData: Off
FileModifyDate: 2006:05:24 12:06:36
AutoRotate: None
Urgency: 5
LongFocal: 400
ColorTempPC1: 3761
AuthorsPosition: TitleValue
CanonImageHeight: 2336
RawJpgSize: Medium
SceneCaptureType: Standard
ShutterCurtainSync: 1st-curtain sync
FileSize: 7 MB
ToningEffect: None
AutoExposureBracketing: Off
YResolution: 72
FilterEffect: None
Aperture: 11.0
FocalPlaneResolutionUnit: inches
FlashOn: Off
SetFunctionWhenShooting: Default (no function)
FNumber: 11.0
MenuButtonDisplayPosition: Previous (top if power off)
CanonFirmwareVersion: Firmware 1.0.4
Self-timer: 0
Shutter-AELock: AF/AE lock
NoiseReduction: Off
Description: Coye Francies before the Spring game.

OwnerName: unknown

-----------------------------------------------------------------------

Thanks again for all your help.

Best regards,

Greg

Archive

[Originally posted by exiftool on 2006-05-25 15:52:27-07]

Now that is a mystery.  Your script works fine here with my test 30D CR2 image.  Here is my terminal session:

Code:
> cp ../pics/Canon30D_IMG_0092.CR2 tmp/a.cr2
> ./exiftool tmp/a.cr2 -imagedescription
> ./ttt
> ./exiftool tmp/a.cr2 -imagedescription
Image Description               : A499JKLLL
> more ttt
#!/usr/bin/perl -w

BEGIN { push @INC, 'lib' }
use Image::ExifTool 'ImageInfo';
#use IO::File;
#use Time::Local;

my $exifTool = new Image::ExifTool;

$photodirectory = "tmp/";
$file = "a.cr2";

my $info = $exifTool->ImageInfo($photodirectory.$file);
$exifTool->SetNewValue("ImageDescription", "A499JKLLL");
$exifTool->WriteInfo($photodirectory.$file);
my $err = $exifTool->GetValue('Error');
$err and warn "Error: $err\n";
my $warn = $exifTool->GetValue('Warning');
$warn and warn "Warning: $warn\n";
exit;
>

Notice I added a few lines at the end of the script to print errors and warnings... they didn't print anything for me, but they might help you diagnose the problem you are having.

- Phil

Archive

[Originally posted by gregkeene on 2006-05-25 16:11:24-07]

I changed my code ti include your errors, here's my code:

Code:
#!/usr/bin/perl -w

BEGIN { push @INC, 'lib' }

use Image::ExifTool 'ImageInfo';
#use IO::File;
#use Time::Local;

my $exifTool = new Image::ExifTool;

$photodirectory = "/Volumes/d\$/PhotoMaster/rawtest/";
$file = "20060429-30D-IMG_4892test.CR2";

my $info = $exifTool->ImageInfo($photodirectory.$file);
$exifTool->SetNewValue("ImageDescription", "A499JKLLL");
$exifTool->WriteInfo($photodirectory.$file);

my $err = $exifTool->GetValue('Error');
$err and warn "Error: $err\n";
my $warn = $exifTool->GetValue('Warning');
$warn and warn "Warning: $warn\n";

exit;

I get this error:

Error: [minor] 2060 unreferenced bytes at end of file not copied

Greg

Archive

[Originally posted by exiftool on 2006-05-25 16:21:54-07]

This is odd.  Did you edit the CR2 with any software which could have added the 2060 byte trailer?  If the image is straight out of the camera, perhaps it is a different firmware version than my sample.  In this case, it would be useful to have a sample so I can determine if this new information is significant.

You can ignore the minor error and force the image to be written by adding this line to your script:

Code:
$exifTool->Options(IgnoreMinorErrors => 1);

But it would be nice to know what the trailer contains before you go and discard it like this.

Archive

[Originally posted by gregkeene on 2006-05-25 17:15:44-07]

These files have had their IPTC tags changed by BreezeBrowser Pro and Photo Mechanic. Other than that, no changes.

I'll send you an email with a link to a few files.

I have 1.0.4 firmware.

Greg

Archive

[Originally posted by exiftool on 2006-05-25 17:57:05-07]

Hi Greg,

Thanks for the samples.  Yup, that's the problem.  One of those two pieces of software is adding a non-standard trailer containing what looks to be an empty IPTC structure.  Deleting this shouldn't affect the image, but you may lose some of the information you added to the image.

You can use ExifTool will write the ImageDescription if you use the IgnoreMinorErrors option, but you will lose this trailer.

Archive

[Originally posted by gregkeene on 2006-05-25 18:16:29-07]

That did it. I'm going to do some testing with both packages from native CR2 files and I'll post my results here.

Thanks again for everything!

Greg

Archive

[Originally posted by exiftool on 2006-05-26 14:30:28-07]

I downloaded Photo Mechanic and ran some tests myself.  The problem is more severe than I thought:

It turns out that editing a CR2 with Photo Mechanic changes it so that ExifTool no longer recognizes it as a CR2 image.  This is because Photo Mechanic relocates IFD0 to an offset which is not the standard CR2 location.  The result is that the image is written as a regular TIFF, so the CR2 header and trailers are lost.

I have just released ExifTool 6.21, which has new logic to identify CR2 images which have been edited by Photo Mechanic.  This version should solve your problems, including preserving the Photo Mechanic trailer.

Anyone writing CR2 images which may have been edited by Photo Mechanic should update to this new version.

- Phil

Archive

[Originally posted by gregkeene on 2006-05-26 15:59:34-07]

Phil:

I downloaded installed and tested 6.21. In doing so I removed the command. So far everything looks good on files that weren't part of my previous testing. However the files that were part of my previous testing with Image::ExifTool and Photo Mechanic are probably toast -- which is why there were test files. They still generate errors. I have no need to recover them, I only mention it for others who might use Photo Mechanic with Image::ExifTool (and probably other tools) on CR2 (and probably other raw formats) -- definitely upgrade.

Phil, thanks again for everything and your amazing responsiveness.

Greg

Archive

[Originally posted by exiftool on 2006-05-26 16:34:12-07]

To clarify the situation:

Your old test files will have lost the CR2 identifier, so they will generate minor errors when you write them.  But they are not toast, and still should be OK when used with most image utilities.  However, it is a good idea to upgrade.

The changes only affect writing of CR2 images.  Other RAW formats don't have an identifier like CR2, so this isn't a problem.  However, you may still get the "[minor] unreferenced bytes" error when writing other TIFF-based RAW formats if they have been edited by Photo Mechanic.  I will look into fixing this for other RAW file types.