summaryrefslogtreecommitdiff
path: root/macros/showReprojectionErrors.sci
blob: 94a77afe3908accd8859ce25adc343f5b192dd16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
function showReprojectionErrors(cameraParameters)
// It displays reprojection errors using bar graph 
//
// Calling Sequence
//   showReprojectionErrors(cameraParameters)
//
// Parameters
// cameraParameters: cameraParameters strucure
//
// Description
//  It visualizes reprojection errors for a single camera or stereo pair if cameras.
//
// Examples
// showReprojectionErrors(cameraParameters);
    [lhs rhs]=argn(0)
    if rhs<1 then
        error(msprintf("Need atleat one argument"));
    elseif ~isstruct(cameraParameters) then
        error(msprintf("Given input is not a valid cameraParameters structure"));
    end

    ReprojectionErrors=cameraParameters.ReprojectionErrors;
    if ~isempty(ReprojectionErrors) then
        ReprojectedPoints=cameraParameters.ReprojectedPoints;
        ReprojectionErrors=cameraParameters.ReprojectionErrors;
        ImagePoints=ReprojectedPoints-ReprojectionErrors;
        totalErr=0;
        rvRows=size(cameraParameters.RotationVectors,'r');
        wpRows=size(cameraParameters.WorldPoints,'r');
        for i=1:rvRows
            err=0;
            for j=1:wpRows
                err=err+((ReprojectedPoints(j,1,i)-ImagePoints(j,1,i))+(ReprojectedPoints(j,2,i)-ImagePoints(j,2,i))).^2;
            end
            totalErr=totalErr+err;
            errors(i)=sqrt(err/wpRows);
        end
        totalPoints=rvRows*wpRows;
        meanReprojectionError=sqrt(totalErr/totalPoints);
    end
    da=gda();
    da.title.text="Mean Reprojection Errors per Image"
    da.title.foreground = 12;
    da.title.font_size = 5;
    da.x_label.text="Images";
    da.x_label.font_style = 3;
    da.x_label.font_size = 3;
    da.x_label.foreground = 3;
    da.x_location = "bottom";
    da.y_label.text="Mean Reprojection Errors";
    da.y_label.font_style = 3;
    da.y_label.font_size = 3;
    da.y_label.foreground = 3;
    da.y_location = "left";
    a=gca();
    bar(a,errors,0.2);    //0.2- width of each bar
endfunction