Caffe classification testing losses are always 0 and top-1 is always -nan - neural-network

I am fine-tuning a pre-trained Caffe model. For some reason, the test iteration always returns loss = 0 and top-1 as -nan. The training iteration values for loss and top-1 look reasonable to me.
I expected that top-1 is figure of accuracy for particular classification and would always range between [0-1] while loss could be float.
Here is the output over 300 iterations, I display results every 100 iterations:
I1002 08:08:24.124348 415 solver.cpp:337] Iteration 0, Testing net (#0)
I1002 08:08:24.221879 415 solver.cpp:404] Test net output #0: loss_aeroplane_1 = 0
I1002 08:08:24.221915 415 solver.cpp:404] Test net output #1: loss_aeroplane_2 = 0
I1002 08:08:24.221930 415 solver.cpp:404] Test net output #2: loss_aeroplane_3 = 0
I1002 08:08:24.221944 415 solver.cpp:404] Test net output #3: loss_aeroplane_4 = 0
I1002 08:08:24.221958 415 solver.cpp:404] Test net output #4: loss_aeroplane_5 = 0
I1002 08:08:24.222059 415 solver.cpp:404] Test net output #11: top-1_aeroplane_1 = -nan
I1002 08:08:24.222121 415 solver.cpp:404] Test net output #12: top-1_aeroplane_2 = -nan
I1002 08:08:24.222144 415 solver.cpp:404] Test net output #13: top-1_aeroplane_3 = -nan
I1002 08:08:24.222167 415 solver.cpp:404] Test net output #14: top-1_aeroplane_4 = -nan
I1002 08:08:24.222190 415 solver.cpp:404] Test net output #15: top-1_aeroplane_5 = -nan
I1002 08:08:27.674801 415 solver.cpp:228] Iteration 0, loss = 0
I1002 08:08:27.674849 415 solver.cpp:244] Train net output #0: loss_aeroplane_1 = 0.015304
I1002 08:08:27.674875 415 solver.cpp:244] Train net output #1: loss_aeroplane_2 = 5.35489
I1002 08:08:27.674890 415 solver.cpp:244] Train net output #2: loss_aeroplane_3 = 0
I1002 08:08:27.674903 415 solver.cpp:244] Train net output #3: loss_aeroplane_4 = 22.1282
I1002 08:08:27.674918 415 solver.cpp:244] Train net output #4: loss_aeroplane_5 = 4.31547
I1002 08:08:27.675045 415 solver.cpp:244] Train net output #11: top-1_aeroplane_1 = 1
I1002 08:08:27.675061 415 solver.cpp:244] Train net output #12: top-1_aeroplane_2 = 0
I1002 08:08:27.675077 415 solver.cpp:244] Train net output #13: top-1_aeroplane_3 = -nan
I1002 08:08:27.675091 415 solver.cpp:244] Train net output #14: top-1_aeroplane_4 = 0
I1002 08:08:27.675112 415 solver.cpp:244] Train net output #15: top-1_aeroplane_5 = 0.5
I1002 08:08:27.675243 415 sgd_solver.cpp:106] Iteration 0, lr = 1e-06
I1002 08:14:02.664109 415 solver.cpp:337] Iteration 100, Testing net (#0)
I1002 08:14:02.720834 415 solver.cpp:404] Test net output #0: loss_aeroplane_1 = 0
I1002 08:14:02.720870 415 solver.cpp:404] Test net output #1: loss_aeroplane_2 = 0
I1002 08:14:02.720908 415 solver.cpp:404] Test net output #2: loss_aeroplane_3 = 0
I1002 08:14:02.720922 415 solver.cpp:404] Test net output #3: loss_aeroplane_4 = 0
I1002 08:14:02.720942 415 solver.cpp:404] Test net output #4: loss_aeroplane_5 = 0
I1002 08:14:02.721050 415 solver.cpp:404] Test net output #11: top-1_aeroplane_1 = -nan
I1002 08:14:02.721076 415 solver.cpp:404] Test net output #12: top-1_aeroplane_2 = -nan
I1002 08:14:02.721098 415 solver.cpp:404] Test net output #13: top-1_aeroplane_3 = -nan
I1002 08:14:02.721122 415 solver.cpp:404] Test net output #14: top-1_aeroplane_4 = -nan
I1002 08:14:02.721133 415 solver.cpp:404] Test net output #15: top-1_aeroplane_5 = -nan
I1002 08:14:06.076464 415 solver.cpp:228] Iteration 100, loss = 0.977386
I1002 08:14:06.076515 415 solver.cpp:244] Train net output #0: loss_aeroplane_1 = 0
I1002 08:14:06.076532 415 solver.cpp:244] Train net output #1: loss_aeroplane_2 = 5.73755
I1002 08:14:06.076545 415 solver.cpp:244] Train net output #2: loss_aeroplane_3 = 0
I1002 08:14:06.076555 415 solver.cpp:244] Train net output #3: loss_aeroplane_4 = 5.3247e-06
I1002 08:14:06.076563 415 solver.cpp:244] Train net output #4: loss_aeroplane_5 = 0
I1002 08:14:06.076637 415 solver.cpp:244] Train net output #11: top-1_aeroplane_1 = -nan
I1002 08:14:06.076644 415 solver.cpp:244] Train net output #12: top-1_aeroplane_2 = 0
I1002 08:14:06.076653 415 solver.cpp:244] Train net output #13: top-1_aeroplane_3 = -nan
I1002 08:14:06.076669 415 solver.cpp:244] Train net output #14: top-1_aeroplane_4 = 1
I1002 08:14:06.076690 415 solver.cpp:244] Train net output #15: top-1_aeroplane_5 = -nan
I1002 08:14:06.076812 415 sgd_solver.cpp:106] Iteration 100, lr = 1e-06
I1002 08:19:40.601531 415 solver.cpp:337] Iteration 200, Testing net (#0)
I1002 08:19:40.658157 415 solver.cpp:404] Test net output #0: loss_aeroplane_1 = 0
I1002 08:19:40.658193 415 solver.cpp:404] Test net output #1: loss_aeroplane_2 = 0
I1002 08:19:40.658202 415 solver.cpp:404] Test net output #2: loss_aeroplane_3 = 0
I1002 08:19:40.658221 415 solver.cpp:404] Test net output #3: loss_aeroplane_4 = 0
I1002 08:19:40.658231 415 solver.cpp:404] Test net output #4: loss_aeroplane_5 = 0
I1002 08:19:40.658363 415 solver.cpp:404] Test net output #11: top-1_aeroplane_1 = -nan
I1002 08:19:40.658376 415 solver.cpp:404] Test net output #12: top-1_aeroplane_2 = -nan
I1002 08:19:40.658387 415 solver.cpp:404] Test net output #13: top-1_aeroplane_3 = -nan
I1002 08:19:40.658407 415 solver.cpp:404] Test net output #14: top-1_aeroplane_4 = -nan
I1002 08:19:40.658418 415 solver.cpp:404] Test net output #15: top-1_aeroplane_5 = 1
I1002 08:19:44.013634 415 solver.cpp:228] Iteration 200, loss = 1.24157
I1002 08:19:44.013686 415 solver.cpp:244] Train net output #0: loss_aeroplane_1 = 1.98091
I1002 08:19:44.013706 415 solver.cpp:244] Train net output #1: loss_aeroplane_2 = 6.87694
I1002 08:19:44.013716 415 solver.cpp:244] Train net output #2: loss_aeroplane_3 = 1.29873
I1002 08:19:44.013727 415 solver.cpp:244] Train net output #3: loss_aeroplane_4 = 17.1241
I1002 08:19:44.013738 415 solver.cpp:244] Train net output #4: loss_aeroplane_5 = 0
I1002 08:19:44.013875 415 solver.cpp:244] Train net output #11: top-1_aeroplane_1 = 0.75
I1002 08:19:44.013890 415 solver.cpp:244] Train net output #12: top-1_aeroplane_2 = 0.5
I1002 08:19:44.013903 415 solver.cpp:244] Train net output #13: top-1_aeroplane_3 = 0
I1002 08:19:44.013917 415 solver.cpp:244] Train net output #14: top-1_aeroplane_4 = 0
I1002 08:19:44.013931 415 solver.cpp:244] Train net output #15: top-1_aeroplane_5 = 1
I1002 08:19:44.014006 415 sgd_solver.cpp:106] Iteration 200, lr = 1e-06
I1002 08:25:19.499899 415 solver.cpp:337] Iteration 300, Testing net (#0)
I1002 08:25:19.556656 415 solver.cpp:404] Test net output #0: loss_aeroplane_1 = 0
I1002 08:25:19.556694 415 solver.cpp:404] Test net output #1: loss_aeroplane_2 = 0
I1002 08:25:19.556702 415 solver.cpp:404] Test net output #2: loss_aeroplane_3 = 0
I1002 08:25:19.556730 415 solver.cpp:404] Test net output #3: loss_aeroplane_4 = 0
I1002 08:25:19.556743 415 solver.cpp:404] Test net output #4: loss_aeroplane_5 = 0
I1002 08:25:19.556854 415 solver.cpp:404] Test net output #11: top-1_aeroplane_1 = -nan
I1002 08:25:19.556874 415 solver.cpp:404] Test net output #12: top-1_aeroplane_2 = -nan
I1002 08:25:19.556893 415 solver.cpp:404] Test net output #13: top-1_aeroplane_3 = -nan
I1002 08:25:19.556913 415 solver.cpp:404] Test net output #14: top-1_aeroplane_4 = -nan
I1002 08:25:19.556931 415 solver.cpp:404] Test net output #15: top-1_aeroplane_5 = -nan
I1002 08:25:22.910521 415 solver.cpp:228] Iteration 300, loss = 1.06406
I1002 08:25:22.910571 415 solver.cpp:244] Train net output #0: loss_aeroplane_1 = 0.776529
I1002 08:25:22.910589 415 solver.cpp:244] Train net output #1: loss_aeroplane_2 = 8.75287
I1002 08:25:22.910600 415 solver.cpp:244] Train net output #2: loss_aeroplane_3 = 4.64917e-06
I1002 08:25:22.910616 415 solver.cpp:244] Train net output #3: loss_aeroplane_4 = 12.4562
I1002 08:25:22.910634 415 solver.cpp:244] Train net output #4: loss_aeroplane_5 = 7.18792
I1002 08:25:22.910776 415 solver.cpp:244] Train net output #11: top-1_aeroplane_1 = 0
I1002 08:25:22.910794 415 solver.cpp:244] Train net output #12: top-1_aeroplane_2 = 0
I1002 08:25:22.910815 415 solver.cpp:244] Train net output #13: top-1_aeroplane_3 = 1
I1002 08:25:22.910849 415 solver.cpp:244] Train net output #14: top-1_aeroplane_4 = 0
I1002 08:25:22.910869 415 solver.cpp:244] Train net output #15: top-1_aeroplane_5 = 0
I1002 08:25:22.910969 415 sgd_solver.cpp:106] Iteration 300, lr = 1e-06
Also, can someone please let me know how is Caffe calculating loss here? Is this 'total loss' (sum of losses for all classes) or what?
I1002 08:25:22.910521 415 solver.cpp:228] Iteration 300, loss = 1.06406

Related

How to "Take Priority" of Audio Playback?

I have an audio-playback app that crashes when returning from another audio-playing app when the user attempts to re-start playback. My app works great on it's own and will handle background playback, etc; however when returning from Spotify-like apps it crashes when it starts it's own playback.
I'm guessing there's some sort of "priority" of audio that I should be handling? And taking that priority "back" from whatever audio app previously had it? Just looking for a direction to start looking....thanks!
Backtrace:
thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
frame #0: 0x00000001be4fdec4 libsystem_kernel.dylib__pthread_kill + 8
frame #1: 0x00000001be41d724 libsystem_pthread.dylibpthread_kill$VARIANT$armv81 + 216
frame #2: 0x00000001be36d844 libsystem_c.dylibabort + 100
frame #3: 0x00000001be4c67d4 libc++abi.dylibabort_message + 128
frame #4: 0x00000001be4c69c4 libc++abi.dylibdemangling_terminate_handler() + 296
frame #5: 0x00000001be42e258 libobjc.A.dylib_objc_terminate() + 124
frame #6: 0x00000001be4d3304 libc++abi.dylibstd::__terminate(void (*)()) + 16
frame #7: 0x00000001be4d2ed8 libc++abi.dylib__cxa_rethrow + 144
frame #8: 0x00000001be42e158 libobjc.A.dylibobjc_exception_rethrow + 40
frame #9: 0x00000001be67eb4c CoreFoundationCFRunLoopRunSpecific + 576
frame #10: 0x00000001c861f328 GraphicsServicesGSEventRunModal + 104
frame #11: 0x00000001c278c63c UIKitCoreUIApplicationMain + 1936
frame #12: 0x00000001047c0e78 Sequencer`main at AppDelegate.swift:23:7
frame #13: 0x00000001be508360 libdyld.dylib`start + 4

SIGABRT in Macos application

I'm getting a SIGBART signal after the application is running a while.
I suspect that it is related to timer which is running in the background.
This is the code I'm using to invoke the recurrent timer:
Timer.scheduledTimer(timeInterval: 20 , target: self, selector: #selector(self.scheduledEventHandler), userInfo: nil, repeats: true)
And this is the handler:
#objc func scheduledEventHandler()
{
print("got event")
}
And lastly, this is the stacktrace:
thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
frame #0: 0x00007fff5182cfce libsystem_kernel.dylib`__pthread_kill + 10
frame #1: 0x0000000100fbb1b4 libsystem_pthread.dylib`pthread_kill + 333
frame #2: 0x00007fff5178930a libsystem_c.dylib`abort + 127
frame #3: 0x00007fff4f76bf8f libc++abi.dylib`abort_message + 245
frame #4: 0x00007fff4f76c12b libc++abi.dylib`default_terminate_handler() + 265
frame #5: 0x00007fff50af0eab libobjc.A.dylib`_objc_terminate() + 105
frame #6: 0x00007fff4f7877c9 libc++abi.dylib`std::__terminate(void (*)()) + 8
frame #7: 0x00007fff4f787478 libc++abi.dylib`__cxa_rethrow + 99
frame #8: 0x00007fff50aef139 libobjc.A.dylib`objc_exception_rethrow + 40
frame #9: 0x00007fff2a0f703e CoreFoundation`CFRunLoopRunSpecific + 638
frame #10: 0x00007fff29416866 HIToolbox`RunCurrentEventLoopInMode + 286
frame #11: 0x00007fff294165d6 HIToolbox`ReceiveNextEventCommon + 613
frame #12: 0x00007fff29416354 HIToolbox`_BlockUntilNextEventMatchingListInModeWithFilter + 64
frame #13: 0x00007fff27713a23 AppKit`_DPSNextEvent + 2085
frame #14: 0x00007fff27ea8e6c AppKit`-[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 3044
frame #15: 0x00007fff27708831 AppKit`-[NSApplication run] + 764
frame #16: 0x00007fff276d79d2 AppKit`NSApplicationMain + 804
frame #17: 0x0000000100034d2d App`main at AppDelegate.swift:15
frame #18: 0x00007fff516dd145 libdyld.dylib`start + 1
frame #19: 0x00007fff516dd145 libdyld.dylib`start + 1
*Please note, that this task works well most of the time (crashes rarely).
I'll appreciate any suggestions to better understand the cause of such crash.

How do I get rid of the subscript indices error in my code?

length = 31 ;
while length < 0
length = input('enter a value greater than 0:')
end
pounds = 26905;
elasticity = 45941267 ;
width = 4.3
while width < 0
width = input('enter a value greater than 0:')
end
height = 1.2
while height < 0
height = input('enter a value greater than 0:');
end
I = (width*height^3)/12;
a = linspace(1,200)';
b = length - a ;
if a >= 0
maximum = (-pounds*b(length.^2-(b.^2))^(3/2))/(9*sqrt(3)*elasticity*I*length)'
elseif b >= 0
maximum = (-pounds*a(length.^2-(a.^2))^(3/2))/(9*sqrt(3)*elasticity*I*length)'
end
It happens at this line:
maximum = (-pounds*b(length.^2-(b.^2))^(3/2))/(9*sqrt(3)*elasticity*I*length)'
I need my code to come out with these numbers so i can print them in a table and be done with my code.
As #rayryeng stated, the problem you hay is that you are indexing into b.
If you examine length^2 - (b.^2) you get:
61 120 177 232 285 336 385 432 477 520
561 600 637 672 705 736 765 792 817 840
861 880 897 912 925 936 945 952 957 960
961 960 957 952 945 936 925 912 897 880
861 840 817 792 765 736 705 672 637 600
561 520 477 432 385 336 285 232 177 120
61 0 -63 -128 -195 -264 -335 -408 -483 -560
... snipped
The fourth value is: 232 which is greater than b's length (200 in this case). That triggers the first error, but even if you were able to continue you'll eventually get to negative values (for an index! Another error there)

least squares with seasonal component in matlab

I was reading a paper which looked at investigating trends in monthly wind speed data for the past 20 years or so. The paper uses a number of different statistical approaches, which I am trying to replicate here.
The first method used is a simple linear regression model of the form
$$ y(t) = a_{1}t + b_{1} $$
where $a_{1}$ and $b_{1}$ can be determined by standard least squares.
Then they specify that some of the potential error in the linear regression model can be removed explicitly by accounting for the seasonal signal by fitting a model of the form:
$$ y(t) = a_{2}t + b_{2}\sin\left(\frac{2\pi}{12t} + c_{2}\right) + d_{2}$$
where coefficients $a_{2}$, $b_{2}$, $c_{2}$, and $d_{2}$ can be determined by least squares. They then go on to specify that this model was also tested with additional harmonic components of 3, 4, and 6 months.
Using the following data as an example:
% 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960
y = [112 115 145 171 196 204 242 284 315 340 360 417 % Jan
118 126 150 180 196 188 233 277 301 318 342 391 % Feb
132 141 178 193 236 235 267 317 356 362 406 419 % Mar
129 135 163 181 235 227 269 313 348 348 396 461 % Apr
121 125 172 183 229 234 270 318 355 363 420 472 % May
135 149 178 218 243 264 315 374 422 435 472 535 % Jun
148 170 199 230 264 302 364 413 465 491 548 622 % Jul
148 170 199 242 272 293 347 405 467 505 559 606 % Aug
136 158 184 209 237 259 312 355 404 404 463 508 % Sep
119 133 162 191 211 229 274 306 347 359 407 461 % Oct
104 114 146 172 180 203 237 271 305 310 362 390 % Nov
118 140 166 194 201 229 278 306 336 337 405 432 ]; % Dec
time = datestr(datenum(yr(:),mo(:),1));
jday = datenum(time,'dd-mmm-yyyy');
y2 = reshape(y,[],1);
plot(jday,y2)
Can anyone demonstrate how the model above can be written in matlab?
Notice that your model is actually linear, we can use a trigonometric identity to show that. To use a nonlinear model use nlinfit.
Using your data I wrote the following script to compute and compare the different methods:
(you can comment out the opts.RobustWgtFun = 'bisquare'; line to see that it's exactly like the linear fit with the 12 periodicity)
% y = [112 115 ...
y2 = reshape(y,[],1);
t=(1:144).';
% trend
T = [ones(size(t)) t];
B=T\y2;
y_trend = T*B;
% least squeare, using linear fit and the 12 periodicity only
T = [ones(size(t)) t sin(2*pi*t/12) cos(2*pi*t/12)];
B=T\y2;
y_sincos = T*B;
% least squeare, using linear fit and 3,4,6,12 periodicities
addharmonics = [3 4 6];
T = [T bsxfun(#(h,t)sin(2*pi*t/h),addharmonics,t) bsxfun(#(h,t)cos(2*pi*t/h),addharmonics,t)];
B=T\y2;
y_sincos2 = T*B;
% least squeare with bisquare weights,
% using non-linear model of a linear fit and the 12 periodicity only
opts = statset('nlinfit');
opts.RobustWgtFun = 'bisquare';
b0 = [1;1;0;1];
modelfun = #(b,x) b(1)*x+b(2)*sin((b(3)+x)*2*pi/12)+b(4);
b = nlinfit(t,y2,modelfun,b0,opts);
% plot a comparison
figure
plot(t,y2,t,y_trend,t,modelfun(b,t),t,y_sincos,t,y_sincos2)
legend('Original','Trend','bisquare weight - 12 periodicity only', ...
'least square - 12 periodicity only','least square - 3,4,6,12 periodicities', ...
'Location','NorthWest');
xlim(minmax(t'));

Camera pose estimation using QR codes in MATLAB

i'm trying to learn camera pose estimation and have been been through quite a lot of material. I want to calculate the pose of the camera using QR codes (quick response code) set up like this on an standard A4:
A0 A1
B0 B1
C0 C1
Took some photos of the QR codes which i printed out on A4 paper, which have dimensions 210mm x 297 mm
This is a short code i wrote in MATLAB to get the coordinates of the world points where i assume the bottom left corner is (0,0)
n=2; %number of qr in x direction
m=3; %number of qr in y direction
x_FE=50; %distance from left edge to point1 in mm
y_FE=270; %distance from bottom to top qr code
sqr_dist=27.6; %distance between qr codes [mm]
sqr_size=47.4; %size of qr code height or width [mm]
QRnames=['A0'; 'A1';'B0'; 'B1';'C0'; 'C1'];
for i=1:n %number of squares in x directions
x1(i)=x_FE+sqr_dist*(i-1);
x2(i)=x_FE+sqr_size+sqr_dist*(i-1);
end
for j=1:m %number of squares in y directions
y1(j)=y_FE-sqr_dist*(j-1);
y2(j)=y_FE-sqr_size-sqr_dist*(j-1);
end
n=1;
for k=1:3 %qr in y direction
for j=1:2 %qr in x direction
p1=[x1(j),y1(k)]
p2=[x1(j),y2(k)]
p3=[x2(j),y2(k)]
p4=[x2(j),y1(k)]
varname1=(['p' int2str(i)]);
varname2=(['x' int2str(j)]);
varname3=(['y' int2str(j)]);
eval([QRnames(n) int2str(j-1) 'w=[p1 p2 p3 p4]' ';' ]);
n=n+1;
end
end
Ive also checked the coordinates by measuring with a ruler
Using a Python script called ZBar which is a QR code reader. i can extract the image coordinates from the QR codes which is embedded in the QR code itself (i think).
The coordinates get saved in a .txt file which is setup this way
QRcode name x1 y1 x2 y2 x3 y3 x4 y4
Here are the images: http://imgur.com/a/xPkWB#0
here are some of the results coordinates:
image2
A0 452 495 454 878 836 878 834 493
B0 455 1099 453 1479 836 1477 836 1099
B1 1056 1099 1056 1477 1442 1481 1442 1096
C0 449 1702 444 2091 831 2093 833 1700
C1 1056 1701 1056 2095 1447 2102 1445 1706
A1 1057 491 1057 878 1443 873 1445 485
image3
A1 1046 375 1051 737 1417 725 1412 364
B0 479 955 482 1316 848 1310 843 950
A0 475 389 477 747 841 740 835 379
B1 1053 946 1058 1307 1426 1302 1421 938
C1 1061 1518 1066 1895 1444 1895 1432 1517
C0 481 1528 479 1901 851 1896 848 1521
image8
A0 528 484 483 738 879 728 891 476
A1 1104 472 1109 728 1512 716 1473 463
B0 452 906 389 1240 852 1237 870 899
B1 1113 896 1119 1234 1595 1226 1540 884
C0 343 1472 248 1957 809 1953 839 1465
C1 1126 1463 1139 1952 1717 1955 1633 1461
image9
A0 2040 560 1741 553 1818 812 2138 811
B0 1562 548 1242 537 1282 806 1625 809
A1 2200 977 1866 980 1969 1311 2325 1301
C0 1047 528 691 515 689 797 1073 804
B1 1665 979 1308 984 1359 1328 1751 1318
C1 1090 983 685 985 677 1359 1119 1340
image10
A1 562 823 943 814 993 517 643 531
B1 1169 805 1571 793 1574 484 1201 504
A0 393 1409 835 1410 907 1010 506 1017
C1 1819 782 2268 768 2209 449 1801 471
B0 1098 1408 1571 1410 1570 997 1146 1003
C0 1862 1415 2390 1420 2309 982 1833 991
Here is information about the camera i used (ipod touch 5.gen):
ExposureTime: 0.0167
FNumber: 2.4000
ExposureProgram: 'Normal program'
ISOSpeedRatings: 32
ExifVersion: [4x1 double]
DateTimeOriginal: '2013:11:23 11:44:52'
DateTimeDigitized: '2013:11:23 11:44:52'
ComponentsConfiguration: 'YCbCr'
ShutterSpeedValue: 5.9069
ApertureValue: 2.5261
BrightnessValue: 5.9402
MeteringMode: 'Pattern'
Flash: [1x148 char]
FocalLength: 3.3000
SubjectArea: [4x1 double]
MakerNote: [196x1 double]
SubsecTimeOriginal: '317'
SubsecTimeDigitized: '317'
FlashpixVersion: [4x1 double]
ColorSpace: 'sRGB'
CPixelXDimension: 1936
CPixelYDimension: 2592
SensingMethod: 'One-chip color area sensor'
SceneType: 'A directly photographed image'
ExposureMode: 'Auto exposure'
WhiteBalance: 'Auto white balance'
DigitalZoomRatio: 1.0021
FocalLengthIn35mmFilm: 33
SceneCaptureType: 'Standard'
UnknownTags: [3x1 struct]
and info about the first test image
info=imfinfo('testimage1002.jpg')
info =
Filename: 'D:\dropbox\Dropbox\campose\testimage_1\testimage1002.jpg'
FileModDate: '23-Nov-2013 11:45:16'
FileSize: 1188331
Format: 'jpg'
FormatVersion: ''
Width: 1936
Height: 2592
BitDepth: 24
ColorType: 'truecolor'
FormatSignature: ''
NumberOfSamples: 3
CodingMethod: 'Huffman'
CodingProcess: 'Sequential'
Comment: {}
Make: 'Apple'
Model: 'iPod touch'
Orientation: 1
XResolution: 72
YResolution: 72
ResolutionUnit: 'Inch'
Software: '7.0.4'
DateTime: '2013:11:23 11:45:16'
YCbCrPositioning: 'Centered'
DigitalCamera: [1x1 struct]
GPSInfo: [1x1 struct]
ExifThumbnail: [1x1 struct]
i read the .txt files and set them up like this
txt=fopen('testimage1002.txt');
datascan01=textscan(txt,'%s%f%f%f%f%f%f%f%f');
QRname01=[datascan01{1}];
x1=[datascan01{2}];
y1=[datascan01{3}];
% point 2
x2=[datascan01{4}];
y2=[datascan01{5}];
% point 3
x3=[datascan01{6}];
y3=[datascan01{7}];
% point 4
x4=[datascan01{8}];
y4=[datascan01{9}];
p1=0;p2=0;p3=0;p4=0;
for n=1:length(datascan01{1})
for i=1:4
for j=1:4
varname1=(['p' int2str(i)]);
varname2=(['x' int2str(i)]);
varname3=(['y' int2str(i)]);
varname4=([QRname01{n}]);
eval(['p' int2str(i) '=[x' int2str(i) '(n)' ' y' int2str(i) '(n)];'])
eval([varname4 '=[p1 p2 p3 p4]' ';' ]);
end
end
end
Now, i have image coordinates and world coordinates and want to find how the camera was standing when the image was captured.
ive looked at Jean- Yves Bouget's Camera Calibration Toolbox but couldnt figure out how to use the functions using QR codes
also looked at 'Finding optimal rotation and translation between corresponding 3D points' (http://nghiaho.com/?page_id=671)
But the resulting rotation matrix, translation vector and rmse seemed wrong. (got rmse=440?)
Calibration matrix
%Image Resolution: 2592 x 1936 pixels
ImgRes=[2592 1936];% pixels
Focallength= 3.3; % mm
%--- Calibration Results ---
% Focals (pixels) -
Fx= 2329.13;
Fy= 2324.04;
% Optical center -
Cx= 1307; Cy= 950.382;
%Radial distortion (Brown's Model)
K1= 0.236384;
K2= -0.680501;
K3= 0;
P1= 0.000319648;
P2= 0.000751849;
%pixel size fx=f/sx
sx=Focallength/Fx;
sy=Focallength/Fy;
distortion = [K1 K2 K3 P1 P2];
Any ideas on how i can do this (hopefully in matlab)? all help is appreciated
Jonathan Brian
The Machine Vision Toolbox for Matlab, by Peter Corke, has the method CentralCamera.estpose described at page 38 of the manual.
The helps says:
CentralCamera.estpose
Estimate pose from object model and camera view
T = C.estpose(xyz, uv) is an estimate of the pose of the object defined
by coordinates xyz (3 x N) in its own coordinate frame. uv (2 x N) are the
corresponding image plane coordinates.
Reference “EPnP: An accurate
O(n) solution to the PnP problem”, V. Lepetit, F. Moreno-Noguer, and
P. Fua, Int. Journal on Computer Vision, vol. 81, pp. 155-166, Feb.
2009.
and since you wrote
Now, i have image coordinates and world coordinates and want to find
how the camera was standing when the image was captured.
it seems to me that you can use that function to estimate the pose.