How to config OpenCv (3)


ทดสอบกันเลย

มาถึงส่วนการเขียนโปรแกรม ครับ ผม เอาโค้ดมาทิ้งไว้ให้แล้วกันครับผม ถ้า ใคร config แล้วรันโค้ดนี้ได้แสดงว่า เอาไปใช้งานได้ เลยครับผม

 

#include "cv.h"
#include "highgui.h"
#include <iostream.h>
#include <stdlib.h>

char wndname[] = "Edge";
char tbarname[] = "Threshold";
int edge_thresh = 1;

IplImage *image = 0, *cedge = 0, *gray = 0, *edge = 0;

// define a trackbar callback
void on_trackbar(int h)
{
    cvSmooth( gray, edge, CV_BLUR, 3, 3, 0, 0 );
    cvNot( gray, edge );

    // Run the edge detector on grayscale
    cvCanny(gray, edge, (float)edge_thresh, (float)edge_thresh*3, 3);
 
    cvZero( cedge );
    // copy edge points
    cvCopy( image, cedge, edge );

    cvShowImage(wndname, cedge);
}

int main( int argc, char** argv )
{
    char* filename = argc == 2 ? argv[1] : (char*)"lena.jpg"; // filename picture
   
    if( (image = cvLoadImage( filename, 1)) == 0 )
        return -1;

    // Create the output image
    cedge = cvCreateImage(cvSize(image->width,image->height), IPL_DEPTH_8U, 3);

    // Convert to grayscale
    gray = cvCreateImage(cvSize(image->width,image->height), IPL_DEPTH_8U, 1);
    edge = cvCreateImage(cvSize(image->width,image->height), IPL_DEPTH_8U, 1);
    cvCvtColor(image, gray, CV_BGR2GRAY);

    // Create a window
    cvNamedWindow(wndname, 1);

    // create a toolbar
    cvCreateTrackbar(tbarname, wndname, &edge_thresh, 100, on_trackbar);

    // Show the image
    on_trackbar(0);

    // Wait for a key stroke; the same function arranges events processing
    cvWaitKey(0);
    cvReleaseImage(&image);
    cvReleaseImage(&gray);
    cvReleaseImage(&edge);
    cvDestroyWindow(wndname);

    return 0;
}

 

หรือไม่ก็ดาวโหลด ตัวนี้ไปลองเลยครับ งืมๆๆ เอามาให้แล้วเผื่อใครยังทำไม่ได้ ถ้าใครมีอะไรสงสัยก็ เมลมาถามได้เลยนะครับผม  download

คำสำคัญ (Tags): #opencv
หมายเลขบันทึก: 98099เขียนเมื่อ 23 พฤษภาคม 2007 16:27 น. ()แก้ไขเมื่อ 15 มิถุนายน 2012 23:08 น. ()สัญญาอนุญาต: จำนวนที่อ่านจำนวนที่อ่าน:


ความเห็น (1)

สวัสดีครับ

ตอน run โปรแกรมมีข้อความฟ้องว่า ไม่พบ cv100.dll ไม่ทราบว่าต้องแก้ไขอย่างไรครับ

ขอบคุณมากครับ

สิริชัย

พบปัญหาการใช้งานกรุณาแจ้ง LINE ID @gotoknow
ClassStart
ระบบจัดการการเรียนการสอนผ่านอินเทอร์เน็ต
ทั้งเว็บทั้งแอปใช้งานฟรี
ClassStart Books
โครงการหนังสือจากคลาสสตาร์ท