Building PROJ.4 Library in Windows

First thing to do is to make sure all libraries are there. This is actually part of pre-application puzzle challenge. But then, the libraries are already in the github repo. This time, I would like to build it myself. just in case there will be another release during this project. I will only cover building under windows.

Using Visual Studio 2010
PROJ.4 usually come with autotools (autoconf and automake) but for VS, PROJ.4 comes with custom makefile (although no solution or VS project file). In order to build this library using visual studio, one can follow these steps:

  1. run cmd.exe as Administrator (this is important since my OS is 64-bit, otherwise it will generate errors with the debug informations)
  2. execute vcvars32.bat from visual studio directory (in my case it’s in VC\bin\vcvars32.bat)
  3. execute “nmake /f makefile.vc”
  4. if you want to install it then execute “nmake /f makefile.vc install-all”. It will then create a PROJ directory at C:\

Using MinGW/MSYS
I tried to build PROJ.4 by calling sh.exe from cmd but it was not seems to work and then I had to run from msys shell (by running msys.bat). BTW, I use latest MinGW distribution (using mingw-get). I guess these steps are similar with the steps to build a package in linux-based systems.

  1. open msys shell
  2. execute “./configure” from proj-x.y.z directory
  3. execute “./make”
  4. execute “./make install”

Notes
The whole building process is faster when using VS than MinGW even when configuring time is ignored. There is an issue though. At first, I was using “mingw32-make” command in which the build cannot be done. When i checked, the version of ‘mingw32-make’ is different with ‘make’. mingw32-make was mapped to later version (3.82.90 i686-pc-mingw32) while ‘make’ command was mapped to earlier version (3.81 i686-pc-msys).

One comment

  1. tyas haryadi · Juli 2, 2013

    saya Tyas Haryadi yang tanya soal penghitungan luas daun kemarin, sdh di grayscale + tresholding… tapi saya mentok di codingnya….
    setelah coding ini gmn ya om selanjutnya? *newbie di delphi

    unit coba2;

    interface

    uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs, DSPack, ExtCtrls, StdCtrls, DirectShow9, DsUtil, Grids;

    type
    TForm1 = class(TForm)
    BtnMulai: TButton;
    BtnFoto: TButton;
    ComboBox1: TComboBox;
    FilterGraph1: TFilterGraph;
    SampleGrabber1: TSampleGrabber;
    Filter1: TFilter;
    VideoWindow1: TVideoWindow;
    Label1: TLabel;
    Panel1: TPanel;
    Image1: TImage;
    Label2: TLabel;
    Hitung: TButton;
    Label3: TLabel;
    Panel2: TPanel;
    Label4: TLabel;
    HasilLuas: TListBox;
    Label5: TLabel;
    Button3: TButton;
    procedure BtnMulaiClick(Sender: TObject);
    procedure BtnFotoClick(Sender: TObject);
    procedure ComboBox1Click(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure Button3Click(Sender: TObject);
    procedure HitungClick(Sender: TObject);

    private
    { Private declarations }
    public
    { Public declarations }
    end;

    var
    Form1: TForm1;
    CapEnum: TSySDevEnum;
    implementation

    {$R *.dfm}

    procedure TForm1.BtnMulaiClick(Sender: TObject);
    var i: integer;
    begin
    CapEnum:=TSysDevEnum.Create(CLSID_VideoInputDeviceCategory);
    For i:=0 to CapEnum.CountFilters-1 do
    begin
    combobox1.Items.Add(CapEnum.Filters[i].FriendlyName);
    end;
    end;

    procedure BitmapGrayscale(const Bitmap: TBitmap);
    var
    i, j: Integer;
    ptr: ^TByteArray;
    begin
    try
    for i := 0 to (Bitmap.Height-1) do
    begin
    ptr := Bitmap.ScanLine[i];
    for j := 0 to (Bitmap.Width-1) do
    begin
    if Bitmap.PixelFormat = pf24bit then
    begin
    ptr[3*j]:=round(0.114* ptr[3*j] + 0.587*ptr[3*j+1] + 0.299*ptr[3*j+2]);
    ptr[3*j+1]:=ptr[3*j];
    ptr[3*j+2]:=ptr[3*j];
    end;
    end;
    end;
    except
    ShowMessage(‘Cannot Complete Operation’);
    end;
    end;

    procedure TEnrollFormThreshold(Image:TBitmap);
    const level=255;
    var
    histogram: array[0..255] of integer;
    PH: PByteArray;
    TotalMean, Variance, maxVariance, zerothCumuMoment, firstCumuMoment : real;
    i,j,k: integer;
    p: PByteArray;
    threshold:byte;
    area: Word;

    begin
    for i:=0 to level do
    begin
    histogram[i]:=0;
    end;
    for i:=0 to Image.Height-1 do
    begin
    PH:=Image.ScanLine[i];
    for j:= 0 to Image.Width-1 do
    begin
    inc(histogram[PH[3*j]]);
    end;
    end;

    //compute otsu method
    threshold:=0;
    totalMean := 0;
    maxVariance := 0;
    firstCumuMoment := 0;
    zerothCumuMoment := 0;
    area := Image.Height * Image.Width;

    for k:= 0 to level do
    TotalMean := TotalMean + (k * histogram[k] / area);

    for k:= 0 to level do
    begin
    zerothCumuMoment := zerothCumuMoment + histogram[k] / area;
    firstCumuMoment := firstCumuMoment + (k * histogram[k] / area);
    variance := totalMean * zerothCumuMoment – firstCumuMoment;
    variance := variance * variance;

    if ((zerothCumuMoment 0) and (zerothCumuMoment 1)) then
    begin
    variance := variance /(zerothCumuMoment * (1 – zerothCumuMoment));

    if (maxVariance threshold then
    p[3*j+k]:= 255
    else
    p[3*j+k]:= 0;
    end;
    end;
    end;

    procedure TForm1.BtnFotoClick(Sender: TObject);
    begin
    samplegrabber1.GetBitmap(Image1.Picture.Bitmap);
    begin
    BitmapGrayscale(Image1.Picture.Bitmap);
    Image1.Refresh;
    begin
    TEnrollFormThreshold(Image1.Picture.Bitmap);
    Image1.Refresh;
    end;
    end;
    end;

    procedure TForm1.ComboBox1Click(Sender: TObject);
    begin
    FilterGraph1.ClearGraph;
    FilterGraph1.Active := false;
    Filter1.BaseFilter.Moniker :=
    capenum.GetMoniker(combobox1.ItemIndex);
    FilterGraph1.Active := true;
    with FilterGraph1 as ICaptureGraphBuilder2 do
    RenderStream(@PIN_CATEGORY_PREVIEW,
    nil, Filter1 as IBaseFilter, SampleGrabber1 as
    IBaseFilter, VideoWindow1 as
    IbaseFilter); FilterGraph1.Play;
    end;

    procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    begin
    capenum.Free;
    FilterGraph1.ClearGraph;
    FilterGraph1.Active := false;
    end;

    procedure TForm1.Button3Click(Sender: TObject);
    begin
    close
    end;

    procedure TForm1.HitungClick(Sender: TObject);
    var
    //Deklarasi untuk ngitung luas
    b1: integer;
    x1,y1 : integer;
    Items : char;
    x,y : integer;

    begin
    //Ngitung luas daun
    //b1:=(TBitmap(Image1.Items [0]));
    //x1 := trunc(x * Image1.Width / b1.Width);
    //y1 := trunc(y * Image1.Height / b1.Height);
    //Graph_x:= 1;
    //Graph_y:= trunc((b1.Canvas.Pixels[x1, y1]and $ff)/4 +20 );

    //Image1.Canvas.Pen.Color := clRed ;
    //Image1.Canvas.MoveTo(Graph_x, Graph_y);
    //for i :=1 to Image1.Count-1 do begin
    //b1 := (TBitmap(Image1.Items [i]));
    //Graph_x:= 10 + x_spacing*i;
    //Graph_y:= b1.Canvas.Pixels[x1, y1] ;
    //Graph_y:= trunc((Graph_y and $ff)/4 + 20);
    //image1.Canvas.LineTo(Graph_x, Graph_y);

    end;
    //FloadToStr(jml/(Image1.Height*Image1.Width)*(6*5));
    //end;

    end.

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s