Main Menu
Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Topics - sodanum

#2
มือใหม่หัดขับ ลองเล่น Ayarafun LamLoei Node32s ตอนนี้กำหนด IP กับทดลองเปิดปิด LED ได้แล้ว
แต่แค่ในวงเลน เลยอยากทดลองใช้ผ่าน internet  เราจะเขียน Code กำหนดเปิด Port ยังไงครับ





#include <WiFi.h>

const char* ssid     = "yourssid";
const char* password = "yourpasswd";

IPAddress local_IP(192, 168, 1, 100);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);
IPAddress primaryDNS(8, 8, 8, 8); //optional
IPAddress secondaryDNS(8, 8, 4, 4); //optional

WiFiServer server(80);

void setup()
{
    Serial.begin(115200);
    pinMode(2, OUTPUT);      // set the LED pin mode
    digitalWrite(2, HIGH);
    delay(10);

   if (!WiFi.config(local_IP, gateway, subnet, primaryDNS, secondaryDNS)) {
    Serial.println("STA Failed to configure");
   }
 
    WiFi.begin(ssid, password);
   
    server.begin();

}

int value = 0;

void loop(){
WiFiClient client = server.available();   // listen for incoming clients

  if (client) {                             // if you get a client,
    Serial.println("New Client.");           // print a message out the serial port
    String currentLine = "";                // make a String to hold incoming data from the client
    while (client.connected()) {            // loop while the client's connected
      if (client.available()) {             // if there's bytes to read from the client,
        char c = client.read();             // read a byte, then
        Serial.write(c);                    // print it out the serial monitor
        if (c == '\n') {                    // if the byte is a newline character

          // if the current line is blank, you got two newline characters in a row.
          // that's the end of the client HTTP request, so send a response:
          if (currentLine.length() == 0) {
            // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
            // and a content-type so the client knows what's coming, then a blank line:
            client.println("HTTP/1.1 200 OK");
            client.println("Content-type:text/html");
            client.println();

            // the content of the HTTP response follows the header:
            client.print("Click <a href=\"/H\">here</a> to turn the LED on pin 2 on.<br>");
            client.print("Click <a href=\"/L\">here</a> to turn the LED on pin 2 off.<br>");

            // The HTTP response ends with another blank line:
            client.println();
            // break out of the while loop:
            break;
          } else {    // if you got a newline, then clear currentLine:
            currentLine = "";
          }
        } else if (c != '\r') {  // if you got anything else but a carriage return character,
          currentLine += c;      // add it to the end of the currentLine
        }

        // Check to see if the client request was "GET /H" or "GET /L":
        if (currentLine.endsWith("GET /H")) {
          digitalWrite(2, LOW[img][/img]);               // GET /H turns the LED on
        }
        if (currentLine.endsWith("GET /L")) {
          digitalWrite(2, HIGH;                // GET /L turns the LED off
        }
      }
    }
    // close the connection:
    client.stop();
    Serial.println("Client Disconnected.");
  }
}

#3
ผมมีพัดลม  HATARI ฮาตาริ HC-I18M5 ใบพัด 18 นิ้ว



Quote- ระบบ thermal fuse ตัดไฟอัตโนมัติ เมื่อมอเตอร์มีอุณหภูมิสูงผิดปกติ

- ขนาดใบพัด (นิ้ว) 18

- แรงดันไฟ (โวลท์) 220

- ความถี่ (เฮิร์ต) 50

- กำลังไฟฟ้า (วัตต์) 126

- กระแสไฟฟ้า (แอมป์) 0.72

- วัสดุฉนวนชนิด E

- ค่าประสิทธิภาพการระบายลม

- (m3/min/w) 1.27

- ระดับแรงลม 3

- สวิตซ์ควบคุมแรงลม หมุนปรับ

ตอนนี้แค่เบอร์ 1 มันก็แรงสุดๆ แล้วครับ พอจะมีวงจรแนะนำหรือเปล่าครับ ถ้าผมอยากจะปรับ
ความแรงของพัดลม โดยให้ความแรงสูงสุดยังเท่าเดิม และสามารถปรับความเร็วให้น้อยกว่าเบอร์ 1 ได้

;D

#4
Camera Show




โปรแกรมทำอะไรได้บ้าง

- ติดตั้งโปรแกรม ถอดโปรแกรม ได้ง่ายๆ(เพิ่งทำเป็น เหอะๆ)
- จับภาพ webcam เป็น file ภาพได้ (Image Capture )
- ปรับขนาดภาพได้ 2 ขนาด 320x240 , 640x480
- กลับภาพซ้ายขวาได้ (เอาไว้เป็นกระจกแต่งหน้าได้)
- กลับภาพบนล่าง
- ทำให้หน้าต่างโปรแกรมอยู่ด้านบนตลอดได้
- ซ่อนเมนูได้ (อันนี้เอาไว้สำหรับคนชอบโชว์ของ... ใช้คู่กับโปรแกรมบันทึกหน้าจอ แล้วอยากให้เห็น ภาพจาก Webcam  ด้วย)




ตัวอย่างการ โชว์ของ.... (ใครคิดลึกไปแล้วยกมือขึ้น)  ;D



>> http://www.electoday.com/index.php/topic,10659.0.html





>> http://www.electoday.com/index.php/topic,10603.0.html



โปรแกรมเขียนขึ้นจาก C# นะครับ ผมเป็นมือสมัครเล่น เจอ Bug ตรงไหนแจ้งให้ทราบได้ครับ

..............
Support
.............
- win 7
- win vita
- win 8
- win 8.1

**เนื่องจากพัฒนาจาก C# จึงจำเป็นต้องมี Microsoft .NET Framework 4.5  ด้วยนะครับ

ลองเอาไปทดสอบเล่นดูครับ.....

Download Link 1>> http://upload.ohozaa.com/download/11652/Camera-Showrar
Download Link 2>> https://www.mediafire.com/?xv36g7bdfk73aeg
#5
Yes My Lord

http://www.youtube.com/v/7CDx7wuWL0I

Yes My Loard ถูกพัฒนาขึ้นจาก C# ผมเป็นมือสมัครเล่น อาจมีข้อผิดพลาด
โปรแกรมไม่ทำงาน งอแง ก็อย่าถึงกับ โกรธเกลียด ผมเลยนะครับ  ;D



สำหรับลูกเล่น พ่อเล่นของโปรแกรม Yes My Lord นี้ก็คือ

- สั่งงานด้วยเสียงภาษาอังกฤษ ถ้าเป็นไทย ต้องเป็น ภาษาคาราโอเกะ.. เช่น ลำยอง/lam yong

- ตอบเป็น เสียงภาษาอังกฤษได้ ใช้ TTS ของ windows เอง

- ตอบเป็น ภาษาไทยได้ แต่ต้องต่อ internet เพราะเอาเสียง ไทยมาจาก google translate ดึงมาแบบ Auto เลย

- ตอบเป็น file เสียงได้ ทั้ง Mp3 และ wav

- สื่อสารข้อมูลกับ arduino ทาง serial port (แบบที่เห็นในคลิป ส่งข้อมูล ไปเปิดปิด LED)

- อื่นๆ ตอนนี้ยังไม่มี ใน V.1 แต่มีแล้ว ใน V หัวผมเอง เหอะๆๆ  ::)

เอาไปลองเล่นกันดูครับ
Download >>  http://upload.ohozaa.com/download/10890/YesMyLordrar


ตัวอย่าง Code Arduino


String inputString = "";         
boolean stringComplete = false; 

void setup()
{
  Serial.begin(9600);
  inputString.reserve(200);

  for(int i=2 ;i<19;i++)
  {
    pinMode(i,OUTPUT);
  }
}

void loop()
{
  if (stringComplete)
  {
    int pin =  stringToNumber(inputString);       
    for(int i=2; i<19; i++)
    {
      if(pin == i*10)digitalWrite(i,LOW);
      if(pin == (i*10)+1)digitalWrite(i,HIGH);
    }             
    inputString = "";
    stringComplete = false;
  }

}

int stringToNumber(String thisString) {
int i, value = 0, length;
length = thisString.length();
for(i=0; i<length; i++) {
value = (10*value) + thisString.charAt(i)-(int) '0';;
}
return value;
}


void serialEvent()
{
while (Serial.available())
{
char inChar = (char)Serial.read();

if (inChar == ' ')
{
stringComplete = true;
}
else
{
inputString += inChar;
}

}
}
#6
ผมได้ชมคลิป ตัวนี้ครับ

การใช้พัดลมให้ได้เหมือนแอร์
http://www.youtube.com/watch?v=5dsa_tfjR5I

เลยเอามาทดลองใช้งานในห้องดูซะเลย งานนี้ ใช้ Arduino + DS18B20  + C#
















จากการทดลอง ประมาณ 20 นาที (1200 วินาที)




8)

อุณหภูมิลดลงประมาณเกือบๆ 1 องศา ช่วงทดลองประมาณ บ่าย 3 - 4 โมง
ดูเหมือนลดลงไม่มาก แต่ที่จับจากความรู้สึกของตัวเอง รู้สึกมันเย็นสบายขึ้น พอสมควรครับ
อาจจะเป็นเพราะอากาศมีการถ่ายเทมากขึ้น เราเลยหายใจได้สะดวกขึ้น
โดยเฉพาะตรงใกล้ๆ หน้าต่าง จะรู้สึกเลยว่ามีลมเย็นเข้ามา...

การทดลองนี้ยังไม่สมบูรณ์เท่าไร จริงๆ ควรต้องมี DS18B20 อีกตัวหนึ่งไว้วัดอุณหภมิ
ภายนอกห้องด้วย พอดีผมมีแค่ตัวเดี่ยว  เอาไว้รอซื้อมาอีกตัวจะมา Update ให้นะครับ

:-*

สำหรับ Arduino ผมใช้ lib ที่ชื่อว่า DallasTemperature  โปรแกรมเลยออกมาสั้นนิดเดียว
(ใช้ lib ก็ดีครับ ง่ายดี แต่ทำให้เราโง่ลงนี้สิ เหอะๆๆ)

Arduino Code

#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

void setup(void)
{
  Serial.begin(9600);
  sensors.begin();
}

void loop(void)
{
  sensors.requestTemperatures();
  Serial.println(sensors.getTempCByIndex(0));   
}




C# Code


    public partial class Form1 : Form
    {

        string RxString;
        uint rxCounter;

        public Form1()
        {
            InitializeComponent();
        }

        private void buttonStart_Click(object sender, EventArgs e)
        {
            serialPort1.PortName = "COM3";
            serialPort1.BaudRate = 9600;
            try { serialPort1.Open(); }
            catch (Exception ex) { MessageBox.Show(ex.Message); }
            if (serialPort1.IsOpen)
            {
                buttonStart.Enabled = false;
                buttonStop.Enabled = true;
                textBox1.ReadOnly = false;
            }

        }

        private void buttonStop_Click(object sender, EventArgs e)
        {
            try
            {
                if (serialPort1.IsOpen)
                {
                    serialPort1.Close();
                    buttonStart.Enabled = true;
                    buttonStop.Enabled = false;
                    textBox1.ReadOnly = true;
                }
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }

        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            try
            {
                if (serialPort1.IsOpen) serialPort1.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }
       
        private void DisplayText(object sender, EventArgs e)
        {
            textBox1.Text = RxString;
            chart1.ChartAreas[0].AxisY.Minimum = 25;
            chart1.ChartAreas[0].AxisY.Maximum = 37;
            chart1.ChartAreas[0].AxisY.Interval = 1;

            chart1.ChartAreas[0].AxisX.Interval = 60;
            chart1.ChartAreas[0].AxisX.Minimum = 0;
            chart1.ChartAreas[0].AxisX.MajorGrid.Enabled = false;
                       
            chart1.ChartAreas[0].AxisY.Title = "C";
            chart1.ChartAreas[0].AxisX.Title = "Time";
           

            chart1.ChartAreas[0].AxisX.MajorGrid.LineColor = Color.Gray;
            chart1.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.Gray;
            chart1.Series[0].Color = Color.Red;
            chart1.Series[0].Points.AddXY(rxCounter, RxString);
        }
        private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
        {
            try
            {
                RxString = serialPort1.ReadLine();
                this.Invoke(new EventHandler(DisplayText));
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }
    }







#7
ช่วงนี้กำลังบ้า C# เลยใช้แต่  Visual Studio พอจับ เจ้า Arduino มาเล่น เลยสงสัยว่า
เราสามารถเขียน โปรแกรม Arduino บน VS ได้หรือเปล่า

ถามอากู๋ ไปเจอกับ  http://www.visualmicro.com/  เลยเก็บมาเล่าให้ฟังครับ

ใครสนใจก็เตรียมเครื่องมือได้เลย

โปรแกรม ที่ต้องใช้

- Arduino 1.0.5  : http://arduino.cc/en/Main/Software   คงมีกันอยู่แล้ว
- Visual Micro (1309.11) : http://visualmicro.codeplex.com/releases/view/105966
- Visual Studio 2012  ( Express  ใช้ไม่ได้นะครับ ต้องเป็น Professional หรือ Ultimate)

วิธีใช้งานเบื้องต้น ดูใน Vdo ละกันครับ..


http://www.youtube.com/v/i-IrsXlPX80


จับ Arduino กับ C# มาอยู่ใน Projects เดี่ยวกัน

http://www.youtube.com/v/95o207zl3Po


สะดวกในการเขียน โปรแกรม Arduino ดีครับ เพราะมันมีตัวช่วยในการเขียนโปรแกรม
พิมพ์คำสั่งแค่บางส่วนมัน show ขึ้นมาเลยว่าเป็นคำสั่งไหน พอ กด tap ก็ลงคำสั่งให้เลย
เหมาะสำหรับคนขึ้ลืมแบบผม จำคำสั่งไม่ค่อยได้  ;D




#8
** Hand of God V1.31 update 29/11/2556 ***

C# + Emgu Cv Libery ตัวเทพสำหรับ คอ  Image processing

หลักการก็คือ ใช้  webcam ตรวจจับมือขวา ว่าเคลื่อนไปทางซ้ายหรือขวา
เข้าหา webcam หรือ ออกจาก webcam
แล้วก็จำลองการกด keyboard เพื่อไปควบคุมโปรแกรมเล่นเพลง ดูหนัง


http://www.youtube.com/v/R7G5zyMoHMo


download ตัวเก่า

Program ตัวเก่า >> http://upload.ohozaa.com/download/10384/Hand-Of-Godrar
C# Code     >>  http://upload.ohozaa.com/download/10382/Hand-Of-God-Coderar

download Hand of God V1.31 ** update 29/11/2556

Download V1.31>> http://www.mediafire.com/download/0ab4i5q3s2jr49c/Hand+Of+God++V1.31.rar




Hand of god V1.31 ตัวนี้พัฒนาขึ้นมาอีกหลายอย่างครับ

มีอะไรใหม่บ้าง

- แก้ปัญหา Bug เปลี่ยนรูปไม่ได้ ของ V1.30

- ติดตั้งถอดโปรแกรมได้ง่ายๆ (เพิ่งทำเป็น)

- เปลี่ยนวิธีตรวจสอบการเคลื่อนที่ใหม่ ทำให้ตรวจจับง่ายกว่าเดิม

- ตั้งค่า Min Size ของ รูปต้นแบบได้ เครื่องไม่แรง ภาพจะไม่กระตุกครับ
ผมลองกับ cpu celeron note book ก็ใช้ได้

- เพิ่มการควบคุมแบบใหม่
# เอามือค้างไว้กับที่
# ขึ้นบน หรือ ลงล่าง แล้วค้างไว้
# ซ้ายไปขวา หรือ ขวาไปซ้าย แล้วค้างไว้

ตัวอย่างเช่น เรา Setup ให้ เคลื่อนมือจาก บนลงล่าง เป็นการลดเสียงเพลง 10%
ถ้าเราต้องการลด 50% ก็ต้อง เคลื่อนมือ 5 รอบ อาจปวดแขนได้

สำหรับ V1.31 เราก็แค่เคลื่อนมือจากบนลงล่างแล้วค้างไว้ จนเสียงเหลือตามที่ต้องการ
แล้วค่อยเอามือออกจากหน้ากล้องได้เลย

รูปแบบการตรวจจับของมือ V1.31



วิธีใช้งานเบื้องต้นครับ (program จะไม่เหมือนกับใน คลิปนะครับ ในคลิปเป็นตัวทดสอบ)

















ทดสอบ






ตัวอย่าง keyboard



#9
Projects / Color Detection with Emgu Cv Library
September 07, 2013, 03:41:21 PM
ช่วงนี้กำลัง หัดเล่น c# อยู่ครับ กะว่าจะเอามาทำอะไรเล่นสนุกๆ กับ Arduino  8)

หลังจากเจ้าพ่อเข้าร่างแล้ว จึงเกิดนิมิต โปรเจค เด็กน้อย ขึ้นในหัว แต่ปัญญามันไม่ตามไป
เลยต้องค่อยๆ ศึกษาหาความรู้ไปที่ละส่วน จะใช้ Processing* เมียหลวง  เขียนขึ้นมา
ก็ไม่เร้าใจซะแล้ว แบบนี้ต้องหนีไปลงอ่าง เอ่ย...  ต้องลอง อะไรใหม่ๆ ให้ชีวิตมีสีสัน กันบาง
ทิ้งเมียเก่า Processing * มาหาอีหนู c#  เด็กใหม่มันสู้มือ  กว่าจะพอรู้เรื่อง อากู๋ บ่น อุบ...

c# ของเขาดีจริง ข้อมูล มากมาย หาความรู้ได้ไม่ยาก เจอ Emgu Cv Library* ที่กลายพันธุ์
มาจาก Open Cv* ให้ชาว c# ได้เล่นแบบง่ายๆ  ยิ่งถูกใจใหญ่
Image processing บนเรียนหนึ่งระหว่างทาง ก่อน ไปถึงโปรเจค เด็กน้อย ที่ตั้งใจไว้

ฮัลเลวังกา แขกขอลาไปกินไอติม...
Color Detection with Emgu Cv Library

http://www.youtube.com/v/c4Dfvn6VQMo


สำหรับความรู้ที่ได้จากบทเรียนแรกนี้ก็คือ ความเข้าใจเรื่องเกี่ยวกับ ระบบสี HSV หรือ HSB

H =  Hue  สีต่างๆ ที่ตาเรามองเห็น ซึ่งถูกแทนด้วยองศา  0 ถึง 360 องศา  สำหรับ Emgu CV จะมีค่าอยู่ที่ 0-180

S = Saturation   ความสดของสี  0 ถึง 100   สดน้อย ถึง สดมาก Emgu Cv มีค่าอยู่ที่ 0-255

B,V =  Brightness คือ ระดับความสว่างและความมืดของสี  0 ถึง 100   ค่า Brightness มาก สีนั้นสว่างมาก  Emgu Cv มีค่าตั้งแต่ 0-255

;D

Download Program>> http://www.mediafire.com/download/ltop3f37v536ifo/Color.rar
Source code >> http://www.mediafire.com/download/oei3ip0xmdeo7jx/Color_detection.rar

ใครสนใจลองเอา Code ไปแกะดูครับ มือใหม่หัดเขียน C# มั่วหน่อยนะครับ.. :-[

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Emgu.CV;
using Emgu.CV.CvEnum;
using Emgu.CV.Structure;
using Emgu.Util;

namespace Color_detection
{
    public partial class Form1 : Form
    {
        #region Globle Var

        private Capture capture;
        private bool captureInProgress;
        private bool imageInProgress;
        String filenameload;
        Image<Bgr, Byte> ImageFrame = new Image<Bgr, Byte>(320, 240);
        Image<Bgr, Byte> ImageHSVwheel = new Image<Bgr, Byte>("HSV-Wheel.png");
        Image<Hsv, Byte> hsvImage = new Image<Hsv, Byte>(0, 0);
        int diff_LH;

        #endregion

        public Form1()
        {
            InitializeComponent();
            imageBox3.Image = ImageHSVwheel;
            Application.Idle += ProcessFrame;
        }

        #region Main Program

        private void ProcessFrame(object sender, EventArgs e)
        {
            if (captureInProgress)
            {
                ImageFrame = capture.QueryFrame();
                ImageFrame = ImageFrame.Resize(imageBox1.Width, imageBox1.Height, Emgu.CV.CvEnum.INTER.CV_INTER_LINEAR);
                imageBox1.Image = ImageFrame;
                ImageProcessing();
            }

            if (imageInProgress)
            {
                ImageFrame = new Image<Bgr, byte>(filenameload);
                int[] whD = scaleImage(ImageFrame.Width, ImageFrame.Height);
                ImageFrame = ImageFrame.Resize(whD[0], whD[1], Emgu.CV.CvEnum.INTER.CV_INTER_LINEAR);
                imageBox1.Image = ImageFrame;
                ImageProcessing();
            }


        }
        private void ImageProcessing()
        {
            Image<Gray, Byte> ImageFrameDetection = cvAndHsvImage(
                ImageFrame,
               Convert.ToInt32(numeric_HL.Value), Convert.ToInt32(numeric_HH.Value),
               Convert.ToInt32(numeric_SL.Value), Convert.ToInt32(numeric_SH.Value),
               Convert.ToInt32(numeric_VL.Value), Convert.ToInt32(numeric_VH.Value),
               checkBox_EH.Checked, checkBox_ES.Checked, checkBox_EV.Checked, checkBox_IV.Checked);

            if (iB2C == 0) imageBox2.Image = ImageFrameDetection;

            if (iB2C == 1)
            {
                Image<Bgr, Byte> imgF = new Image<Bgr, Byte>(ImageFrame.Width, ImageFrame.Height);
                Image<Bgr, Byte> imgD = ImageFrameDetection.Convert<Bgr, Byte>();
                CvInvoke.cvAnd(ImageFrame, imgD, imgF, IntPtr.Zero);
                imageBox2.Image = imgF;
            }

            if (iB2C == 2)
            {
                Image<Bgr, Byte> imgF = new Image<Bgr, Byte>(ImageFrame.Width, ImageFrame.Height);
                Image<Bgr, Byte> imgD = ImageFrameDetection.Convert<Bgr, Byte>();
                CvInvoke.cvAnd(ImageFrame, imgD, imgF, IntPtr.Zero);
                for (int x = 0; x < imgF.Width; x++)
                    for (int y = 0; y < imgF.Height; y++)
                    {
                        {
                            Bgr c = imgF[y, x];
                            if (c.Red == 0 && c.Blue == 0 && c.Green == 0)
                            {
                                imgF[y, x] = new Bgr(255, 255, 255);
                            }
                        }
                    }

                imageBox2.Image = imgF;
            }


            if (checkBox_VAr.Checked) RecDetection(ImageFrameDetection, ImageFrame, trackBar_VAr.Value);

            Image<Gray, Byte> ImageHSVwheelDetection = cvAndHsvImage(
               ImageHSVwheel,
               Convert.ToInt32(numeric_HL.Value), Convert.ToInt32(numeric_HH.Value),
               Convert.ToInt32(numeric_SL.Value), Convert.ToInt32(numeric_SH.Value),
               Convert.ToInt32(numeric_VL.Value), Convert.ToInt32(numeric_VH.Value),
               checkBox_EH.Checked, checkBox_ES.Checked, checkBox_EV.Checked, checkBox_IV.Checked);
            imageBox4.Image = ImageHSVwheelDetection;
        }

        #endregion

        #region Image Processing

        private void RecDetection(Image<Gray, Byte> img, Image<Bgr, Byte> showRecOnImg, int areaV)
        {
            Image<Gray, Byte> imgForContour = new Image<Gray, byte>(img.Width, img.Height);
            CvInvoke.cvCopy(img, imgForContour, System.IntPtr.Zero);


            IntPtr storage = CvInvoke.cvCreateMemStorage(0);
            IntPtr contour = new IntPtr();

            CvInvoke.cvFindContours(
                imgForContour,
                storage,
                ref contour,
                System.Runtime.InteropServices.Marshal.SizeOf(typeof(MCvContour)),
                Emgu.CV.CvEnum.RETR_TYPE.CV_RETR_EXTERNAL,
                Emgu.CV.CvEnum.CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_NONE,
                new Point(0, 0));


            Seq<Point> seq = new Seq<Point>(contour, null);

            for (; seq != null && seq.Ptr.ToInt64() != 0; seq = seq.HNext)
            {
                Rectangle bndRec = CvInvoke.cvBoundingRect(seq, 2);
                double areaC = CvInvoke.cvContourArea(seq, MCvSlice.WholeSeq, 1) * -1;
                if (areaC > areaV)
                {
                    CvInvoke.cvRectangle(showRecOnImg, new Point(bndRec.X, bndRec.Y),
                        new Point(bndRec.X + bndRec.Width, bndRec.Y + bndRec.Height),
                        new MCvScalar(0, 0, 255), 2, LINE_TYPE.CV_AA, 0);
                }

            }

        }
        private Image<Gray, Byte> cvAndHsvImage(Image<Bgr, Byte> imgFame, int L1, int H1, int L2, int H2, int L3, int H3, bool H, bool S, bool V, bool I)
        {
            Image<Hsv, Byte> hsvImage = imgFame.Convert<Hsv, Byte>();
            Image<Gray, Byte> ResultImage = new Image<Gray, Byte>(hsvImage.Width, hsvImage.Height);
            Image<Gray, Byte> ResultImageH = new Image<Gray, Byte>(hsvImage.Width, hsvImage.Height);
            Image<Gray, Byte> ResultImageS = new Image<Gray, Byte>(hsvImage.Width, hsvImage.Height);
            Image<Gray, Byte> ResultImageV = new Image<Gray, Byte>(hsvImage.Width, hsvImage.Height);

            Image<Gray, Byte> img1 = inRangeImage(hsvImage, L1, H1, 0);
            Image<Gray, Byte> img2 = inRangeImage(hsvImage, L2, H2, 1);
            Image<Gray, Byte> img3 = inRangeImage(hsvImage, L3, H3, 2);
            Image<Gray, Byte> img4 = inRangeImage(hsvImage, 0, L1, 0);
            Image<Gray, Byte> img5 = inRangeImage(hsvImage, H1, 180, 0);

            #region checkBox Color Mode

            if (H)
            {
                if (I)
                {
                    CvInvoke.cvOr(img4, img5, img4, System.IntPtr.Zero);
                    ResultImageH = img4;
                }
                else { ResultImageH = img1; }
            }

            if (S) ResultImageS = img2;
            if (V) ResultImageV = img3;

            if (H && !S && !V) ResultImage = ResultImageH;
            if (!H && S && !V) ResultImage = ResultImageS;
            if (!H && !S && V) ResultImage = ResultImageV;

            if (H && S && !V)
            {
                CvInvoke.cvAnd(ResultImageH, ResultImageS, ResultImageH, System.IntPtr.Zero);
                ResultImage = ResultImageH;
            }

            if (H && !S && V)
            {
                CvInvoke.cvAnd(ResultImageH, ResultImageV, ResultImageH, System.IntPtr.Zero);
                ResultImage = ResultImageH;
            }

            if (!H && S && V)
            {
                CvInvoke.cvAnd(ResultImageS, ResultImageV, ResultImageS, System.IntPtr.Zero);
                ResultImage = ResultImageS;
            }

            if (H && S && V)
            {
                CvInvoke.cvAnd(ResultImageH, ResultImageS, ResultImageH, System.IntPtr.Zero);
                CvInvoke.cvAnd(ResultImageH, ResultImageV, ResultImageH, System.IntPtr.Zero);
                ResultImage = ResultImageH;
            }
            #endregion

            CvInvoke.cvErode(ResultImage, ResultImage, (IntPtr)null, 1);

            return ResultImage;
        }
        private Image<Gray, Byte> inRangeImage(Image<Hsv, Byte> hsvImage, int Lo, int Hi, int con)
        {
            Image<Gray, Byte> ResultImage = new Image<Gray, Byte>(hsvImage.Width, hsvImage.Height);
            Image<Gray, Byte> IlowCh = new Image<Gray, Byte>(hsvImage.Width, hsvImage.Height, new Gray(Lo));
            Image<Gray, Byte> IHiCh = new Image<Gray, Byte>(hsvImage.Width, hsvImage.Height, new Gray(Hi));
            CvInvoke.cvInRange(hsvImage[con], IlowCh, IHiCh, ResultImage);
            return ResultImage;
        }
        private int[] scaleImage(int wP, int hP)
        {
            int[] dR = new int[2];
            int ra;
            if (wP != 0)
            {
                ra = (100 * 320) / wP;
                wP = 320;
                hP = (hP * ra) / 100;
                if (hP != 0 && hP > 240)
                {
                    ra = (100 * 240) / hP;
                    hP = 240;
                    wP = (wP * ra) / 100;
                }
                dR[0] = wP;
                dR[1] = hP;
            }
            return dR;
        }

        #endregion

        #region // Tooth Even

        private void numeric_Lo_ValueChanged(object sender, EventArgs e)
        {
            trackBar_HL.Value = Convert.ToInt32(numeric_HL.Value);
            trackBar_SL.Value = Convert.ToInt32(numeric_SL.Value);
            trackBar_VL.Value = Convert.ToInt32(numeric_VL.Value);
        }
        private void numeric_Hi_ValueChanged(object sender, EventArgs e)
        {
            trackBar_HH.Value = Convert.ToInt32(numeric_HH.Value);
            trackBar_SH.Value = Convert.ToInt32(numeric_SH.Value);
            trackBar_VH.Value = Convert.ToInt32(numeric_VH.Value);

        }
        private void numeric_VAr_ValueChanged(object sender, EventArgs e)
        {
            trackBar_VAr.Value = Convert.ToInt32(numeric_VAr.Value);
        }

        private void trackBar_Lo_ValueChanged(object sender, EventArgs e)
        {
            if (trackBar_HL.Value >= trackBar_HH.Value && !checkBox_LH.Checked)
                trackBar_HH.Value = trackBar_HL.Value;
            if (checkBox_LH.Checked && trackBar_HL.Value + diff_LH <= 180)
                trackBar_HH.Value = trackBar_HL.Value + diff_LH;
            numeric_HL.Value = trackBar_HL.Value;
            numeric_SL.Value = trackBar_SL.Value;
            numeric_VL.Value = trackBar_VL.Value;
        }
        private void trackBar_Hi_ValueChanged(object sender, EventArgs e)
        {
            if (trackBar_HH.Value <= trackBar_HL.Value && !checkBox_LH.Checked)
                trackBar_HL.Value = trackBar_HH.Value;

            if (checkBox_LH.Checked && trackBar_HH.Value - diff_LH >= 0)
                trackBar_HL.Value = trackBar_HH.Value - diff_LH;

            numeric_HH.Value = trackBar_HH.Value;
            numeric_SH.Value = trackBar_SH.Value;
            numeric_VH.Value = trackBar_VH.Value;
        }
        private void trackBar_VAr_ValueChanged(object sender, EventArgs e)
        {
            numeric_VAr.Value = trackBar_VAr.Value;
        }

        private void checkBox_LH_CheckedChanged(object sender, EventArgs e)
        {
            diff_LH = trackBar_HH.Value - trackBar_HL.Value;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            imageInProgress = false;

            if (capture == null)
            {
                try
                {
                    capture = new Capture();
                }
                catch (NullReferenceException excpt)
                {
                    MessageBox.Show(excpt.Message);
                }
            }

            if (capture != null)
            {
                if (captureInProgress)
                {
                    captureInProgress = false;
                }
                else
                {
                    captureInProgress = true;
                }
            }
        }
        private void button2_Click(object sender, EventArgs e)
        {
            captureInProgress = false;
            OpenFileDialog OpenFile = new OpenFileDialog();
            if (OpenFile.ShowDialog() == DialogResult.OK)
            {
                filenameload = OpenFile.FileName;
                imageInProgress = true;
            }
        }
        private void button3_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        private void button5_Click(object sender, EventArgs e)
        {
            trackBar_HH.Value = 0;
            trackBar_HL.Value = 0;
            trackBar_SH.Value = 255;
            trackBar_SL.Value = 0;
            trackBar_VH.Value = 255;
            trackBar_VL.Value = 0;
            checkBox_LH.Checked = false;
            checkBox_IV.Checked = false;

        }

        bool ib3C;
        int ib3C_HV, ib3C_Lable_X, ib3C_Lable_Y;
        private void imageBox3_MouseClick(object sender, MouseEventArgs e)
        {
            Image<Hsv, Byte> imgHsv = ImageHSVwheel.Convert<Hsv, Byte>();
            Hsv hsv = imgHsv[e.Y, e.X];
            if (!ib3C)
            {
                ib3C_HV = Convert.ToInt32(hsv.Hue);
                ib3C_Lable_X = imageBox3.Location.X + e.X;
                ib3C_Lable_Y = imageBox3.Location.Y + e.Y;
                label_L.Location = new Point(ib3C_Lable_X, ib3C_Lable_Y);
                label_H.Hide();
            }
            if (ib3C)
            {
                label_H.Show();
                if (ib3C_HV < hsv.Hue)
                {
                    trackBar_HL.Value = ib3C_HV;
                    trackBar_HH.Value = Convert.ToInt32(hsv.Hue);
                    label_H.Location = new Point(imageBox3.Location.X + e.X, imageBox3.Location.Y + e.Y);                   
                }
                else
                {
                    trackBar_HH.Value = ib3C_HV;
                    trackBar_HL.Value = Convert.ToInt32(hsv.Hue);
                    ib3C_HV = 0;
                    label_H.Location = new Point(ib3C_Lable_X, ib3C_Lable_Y);
                    label_L.Location = new Point(imageBox3.Location.X + e.X, imageBox3.Location.Y + e.Y);
                }
            }
            ib3C = !ib3C;
        }

        int iB2C;
        private void imageBox2_Click(object sender, EventArgs e)
        {
            iB2C++;
            if (iB2C > 2) iB2C = 0;
        }

        #endregion

    }
}



Visual Studio Express 2012*  http://www.microsoft.com/visualstudio/eng/products/visual-studio-express-products
Emgu CV Library* http://www.emgu.com/wiki/index.php/Main_Page
Open CV* http://opencv.org/
processing * http://www.processing.org/


:'(

ไอ้โน่ นอนรอ พ่อมันจบหลักสูตร..