⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pointset.cpp

📁 基于OPenCV的源码
💻 CPP
字号:
#include "cxcore.h"#include "highgui.h"#include <stdio.h>CvSeq* point_seq = 0;IplImage* canvas = 0;CvScalar* colors = 0;int pos = 10;int is_equal( const void* _a, const void* _b, void* userdata ){    CvPoint a = *(const CvPoint*)_a;    CvPoint b = *(const CvPoint*)_b;    double threshold = *(double*)userdata;    return (double)(a.x - b.x)*(a.x - b.x) + (double)(a.y - b.y)*(a.y - b.y) <= threshold;}void on_track( int pos ){    CvSeq* labels = 0;    double threshold = pos*pos;    int i, class_count = cvSeqPartition( point_seq, 0, &labels, is_equal, &threshold );    printf("%4d classes\n", class_count );    cvZero( canvas );    for( i = 0; i < labels->total; i++ )    {        CvPoint pt = *(CvPoint*)cvGetSeqElem( point_seq, i );        CvScalar color = colors[*(int*)cvGetSeqElem( labels, i )];        cvCircle( canvas, pt, 1, color, -1 );    }    cvShowImage( "points", canvas );}int main( int argc, char** argv ){    CvMemStorage* storage = cvCreateMemStorage(0);    point_seq = cvCreateSeq( CV_32SC2, sizeof(CvSeq), sizeof(CvPoint), storage );    CvRNG rng = cvRNG(0xffffffff);    int width = 500, height = 500;    int i, count = 1000;    canvas = cvCreateImage( cvSize(width,height), 8, 3 );    colors = (CvScalar*)cvAlloc( count*sizeof(colors[0]) );    for( i = 0; i < count; i++ )    {        CvPoint pt;        int icolor;        pt.x = cvRandInt( &rng ) % width;        pt.y = cvRandInt( &rng ) % height;        cvSeqPush( point_seq, &pt );        icolor = cvRandInt( &rng ) | 0x00404040;        colors[i] = CV_RGB(icolor & 255, (icolor >> 8)&255, (icolor >> 16)&255);    }    cvNamedWindow( "points", 1 );    cvCreateTrackbar( "threshold", "points", &pos, 50, on_track );    on_track(pos);    cvWaitKey(0);    return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -