Monthly Archives: August 2011

OpenCV-2.1.0 using CMake and Visual C++ 2010

Test on Windows7 SP1 32-bit

Pre-Requisites

ขั้นตอนการคอมไพล์ OpenCV-2.1.0 ด้วย CMake และ Visual C++ 2010

  1. เตรียม Solution ของ OpenCV 2.1.0 ด้วย CMake
  2. Build OpenCV 2.1.0 Solution ด้วย Visual C++ 2010
  3. สร้างโปรเจ็กส์ HelloWorld บน Visual C++ 2010
    • Configure Project Directories

เตรียม Solution ของ OpenCV 2.1.0 ด้วย CMake

  1. Download OpenCV-2.1.0-win.zip
  2. Extract to ‘C:\Program Files\’
  3. Create new folder: ‘C:\Program Files\OpenCV-2.1.0\build
  4. Start -> Programs -> CMake 2.8 -> CMake (cmake-gui).
    • Where is the source code: ‘C:/Program Files/OpenCV-2.1.0/’
    • Where to build the binaries: ‘C:/Program Files/OpenCV-2.1.0/buildopencv_cmake01
  5. Click ‘Configure‘ button
    • Specify the generator for this project: Visual Studio 10
    • select Use default native compilers
      opencv_cmake02
  6. Click ‘Configure‘ buttonopencv_cmake03opencv_cmake04
  7. Click ‘Generate‘ buttonopencv_cmake05

Build OpenCV 2.1.0 Solution

Start -> Programs -> Microsoft Visual Studio 2010  -> Microsoft Visual C++ 2010

  • File -> Open -> Project/Solution…’C:\Program Files\OpenCV-2.1.0\build\OpenCV.slnopencv_cmake06
  • After MSVC has finished parsing all of the files (It will say ‘Ready‘ in the bottom left corner): Build -> Build Solutionopencv_cmake07opencv_cmake08
  • After some time, OpenCV should build successfully.opencv_cmake09

สร้างโปรเจ็กส์ HelloWorld

  • To permanantly include necessary .dll files, add ‘C:\Program Files\OpenCV-2.1.0\build\bin\Debug‘ to PATH by visiting Advanced tab in System of Windows. (add to system path manually)
    opencv_cmake10
  • Start -> Programs -> Microsoft Visual Studio 2010 -> Microsoft Visual C++ 2010
    • File -> New -> Project
    • Name: ‘OpenCV_Helloworld‘…’OK’…’Finish’
      opencv_cmake11

Configure Project Directories

  • Project -> OpenCV_Helloworld Properties…Configuration Properties -> VC++ Directories
  • Include Directories…add: ‘C:\Program Files\OpenCV-2.1.0\include\opencv;’
  • Library Directories…add: ‘C:\Program Files\OpenCV-2.1.0\build\lib\Debug;’
  • Source Directories…add: ‘C:\Program Files\OpenCV-2.1.0\src\cv;C:\Program Files\OpenCV-2.1.0\src\cvaux;C:\Program Files\OpenCV-2.1.0\src\cxcore;C:\Program Files\OpenCV-2.1.0\src\highgui;C:\Program Files\OpenCV-2.1.0\src\ml;’
    opencv_cmake12
  • Linker -> Input -> Additional Dependencies…add: ‘cv210d.lib;cxcore210d.lib;highgui210d.lib;
    opencv_cmake13
  • copy image test to project directory
    opencv_cmake14
#include "stdafx.h"

#include <cv.h>
#include <cxcore.h>
#include <highgui.h>

int _tmain(int argc, _TCHAR* argv[]) {
    IplImage *img = cvLoadImage("funny-pictures-cat-goes-pew.jpg");
    cvNamedWindow("Image:",1);
    cvShowImage("image:",img);

    cvWaitKey();
    cvDestroyWindow("Image:");
    cvReleaseImage(&img);

    return 0;
}

ที่มา: OpenCV-2.1.0 using CMake and Visual C++ 2010 Express on Windows XP SP3 32-bit

ปล. ติดตั้งจาก OpenCV-2.1.0-win32-vs2008.exe (ไม่ได้ใช้ CMake) แล้วกำหนดค่า Proproties ของ Project ตามข้างบนแล้ว แต่เวลา run แล้วเกิด Error ดังนี้ “The application was unable to start correctly (0xc0150002)” ทางแก้คือ เปลี่ยนจาก ‘cv210d.lib;cxcore210d.lib;highgui210d.lib;‘  เป็น ‘cv210.lib;cxcore210.lib;highgui210.lib;‘ http://opencv-users.1802565.n2.nabble.com/Application-failed-to-start-correctly-0xc0150002-td4107823.html

ทิปวิธีจับภาพหน้าจอบน iPad

เปิดไปยังหน้าต่างที่ต้องการ หรือโปรแกรมใดๆ
กดปุ่ม Home และปุ่ม Power พร้อมกัน สัก 1-2 วินาที (ถ้านานกว่านั้นจะกลายเป็นปิดเครื่อง)
โปรแกรมจะจับภาพหน้าจอและนำไปเก็บไว้ในหัวข้อ Photos
แค่นี้เราก็สามารถจับภาพหน้าจอของ iPad ได้แล้วครับ
ที่มา: it-guides.com

File and Directory Manipulation

using System.IO;
class TestDirectory {
public static void Main() {
Directory.CreateDirectory(“C:\\csharp”);
}
}

The above lines of codes will create a directory in your C:
Please note that the backslash(\) should be escaped by another backslash since it is a escape character. Moreover, remember to “using” the System.IO namespace so as to use these classes.
Following are a list of useful methods:

1. To create a subdirectory “dump” in C:\csharp just created:
Directory.CreateDirectory(“C:\\csharp\\hello”);

2. To move a directory from one place to another:
Directory.Move(“C:\\csharp\\hello”, “C:\\hello”);

3. To delete a directory:
Directory.Delete(“C:\\hello”);

4. To copy a file to another location, or to a different name:
File.Copy( “c:\\friends.jpg”, “c:\\temp\\abc.jpg”);

5. To move a file from one place to another:
File.Move( “c:\\friends.jpg”, “c:\\temp\\friends.jpg”);

6. To delete a file:
File.Delete( “c:\\friends.jpg” );

Ref: http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=54

How to Create a Microsoft Word Document with C#

object oMissing = System.Reflection.Missing.Value;

Microsoft.Office.Interop.Word.Application oWord;
oWord = new Microsoft.Office.Interop.Word.Application();
oWord.Visible = true;

Microsoft.Office.Interop.Word.Document oDoc;
oDoc = oWord.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);

// add text
Microsoft.Office.Interop.Word.Paragraph oPara1;
oPara1 = oDoc.Paragraphs.Add(ref oMissing);
object styleHeading1 = “Heading 1”;
oPara1.Range.set_Style(ref styleHeading1);
oPara1.Range.Text = “Create a New Report”;
oPara1.Range.InsertParagraphAfter();

Microsoft.Office.Interop.Word.Paragraph oPara2;
oPara2 = oDoc.Paragraphs.Add(ref oMissing);
oPara2.Range.Text = “”;
oPara2.Range.InsertParagraphAfter();

Microsoft.Office.Interop.Word.Paragraph oPara3;
oPara3 = oDoc.Paragraphs.Add(ref oMissing);
oPara3.Range.Text = “This is my second paragraph.”;
oPara3.Range.InsertParagraphAfter();

// add picture
string imgName = “c://tmp/doc1.jpg”;  //the picture file to be inserted
Object oMissed = oDoc.Paragraphs[2].Range; //the position you want to insert
Object oLinkToFile = false;  //default
Object oSaveWithDocument = true;//default
oDoc.InlineShapes.AddPicture(imgName, ref  oLinkToFile, ref  oSaveWithDocument, ref  oMissed);

// save
object fileName = “C:\\tmp\\test_report.doc”;
oDoc.SaveAs(ref fileName, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
oDoc.Close(ref oMissing, ref oMissing, ref oMissing);
oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
oWord = null; // Free up any memory used

Word Object Model Overview
Ref: suite101.com