opencv里像素点获取和染色
程序代码:
#include <stdio.h> #include <cv.h> #include <highgui.h> #define IMAGE_SIZE 1000 int mSetTest(double c_re, double c_im) { int N=0; double real=0,comp=0; int i=0; while(N<4&&i<200) { N=real*real+comp*comp; real=real*real-comp*comp+c_re; comp=2*real*comp+c_im; i++; } if(i<200) return i-1; else return 0; } int main(int argc, char *argv[]) { IplImage *pImg = cvCreateImage (cvSize (IMAGE_SIZE, IMAGE_SIZE), 8, 3); cvNamedWindow ("mandelbrot", 1); cvShowImage ("mandbrot", pImg); CvScalar sca; for(int i=0; i<IMAGE_SIZE; i++) { for(int j=0; j<IMAGE_SIZE; j++) { int m=mSetTest(i,j); if(m==0) { sca.val[0]=111; //blue sca.val[1]=111; //green sca.val[2]=111; //red } else { sca.val[0]=255; sca.val[1]=255; sca.val[2]=255; } } } cvWaitKey (0); cvDestroyWindow ("mandlbrot"); cvReleaseImage(&pImg); return 0; }