C语言画图源程序

C语言画图源程序,第1张

不是仿庆非常理想,但马马虎虎吧。

#include <graphics.h>

#include <stdlib.h>

#include <搏余stdio.h>

#include <conio.h>

#include <time.h>

int main(void)

{

int i,j

int gdriver = DETECT, gmode, errorcode

int maxx, maxy,maxc

int xc,yc,rc,cc /*circle*/

int xr,yr,wr,hr,cr/*rectangle*/

int xt,yt,st,ct/*text*/

char *c

int dx=50,dy=40

initgraph(&gdriver, &gmode, "")

errorcode = graphresult()

if (errorcode != grOk)

{

printf("Graphics error: %s\n", grapherrormsg(errorcode))

printf("Press any key to halt:")

getch()

exit(1)

}

randomize()

maxx = getmaxx()

maxy = getmaxy()

maxc = getmaxcolor()

setcolor(maxc)

while(!kbhit())

{

cleardevice()

xc=dx+(maxx-2*dx-10)*1.0*rand()/RAND_MAX

yc=dy+(maxy-2*dy-10)*1.0*rand()/RAND_MAX

rc=dy*1.0*rand()/RAND_MAX

cc=(maxc-1)*1.0*rand()/RAND_MAX

setcolor(cc)

circle(xc,yc,rc)

setfillstyle(SOLID_FILL,cc)

floodfill(xc,yc,cc)

xr=dx+(maxx-2*dx-10)*1.0*rand()/RAND_MAX

yr=dy+(maxy-2*dy-10)*1.0*rand()/RAND_MAX

wr=dx*1.0*rand()/RAND_MAX

hr=dy*1.0*rand()/RAND_MAX

cr=(maxc-1)*1.0*rand()/RAND_MAX

setcolor(cr)

rectangle(xr-wr/2,yr-hr/2,xr+wr/2,yr+hr/2)

setfillstyle(SOLID_FILL,cr)

floodfill(xr,yr,cr)

xt=dx+(maxx-2*dx-10)*1.0*rand()/RAND_MAX

yt=dy+(maxy-2*dy-10)*1.0*rand()/RAND_MAX

st=dy*1.0*rand()/RAND_MAX

ct=(maxc-1)*1.0*rand()/基大滚RAND_MAX

c[0]='A'+26.0*rand()/RAND_MAX

c[1]='\0'

setcolor(ct)

settextjustify(LEFT_TEXT, TOP_TEXT)

settextstyle(DEFAULT_FONT,HORIZ_DIR,st)

outtextxy(xt,yt,c)

sleep(1)

}

getch()

closegraph()

return 0

}

//声明IplImage指针

IplImage* pFrame = NULL

IplImage* pFrImg = NULL

IplImage* pBkImg = NULL

CvMat* pFrameMat = NULL

CvMat* pFrMat = NULL

CvMat* pBkMat = NULL

pBkImg = cvCreateImage(cvSize(pFrame->width, pFrame->height), IPL_DEPTH_8U,1)

pFrImg = cvCreateImage(cvSize(pFrame->width, pFrame->height), IPL_DEPTH_8U,1)

pBkMat = cvCreateMat(pFrame->height, pFrame->width, CV_32FC1)

pFrMat = cvCreateMat(pFrame->height, pFrame->width, CV_32FC1)

pFrameMat = cvCreateMat(pFrame->height, pFrame->width, CV_32FC1)

//转化成单通道图像再处理

cvCvtColor(pFrame, pBkImg, CV_BGR2GRAY)

cvCvtColor(pFrame, pFrImg, CV_BGR2GRAY)

cvConvert(pFrImg, pFrameMat)

cvConvert(pFrImg, pFrMat)

cvConvert(pFrImg, pBkMat)

//二值化前景图

cvThreshold(pFrMat, pFrImg, 60, 255.0, CV_THRESH_BINARY)

不知道宏蔽慧你说的什么意思,要对一个图像进行二值化处理用OpenCV的话就是

void cvThreshold( const CvArr* src, CvArr* dst, double threshold,

double max_value, int threshold_type )

这个函数是定阈并激值二值蔽答化处理,比较粗略吧。另外可以用自适应阈值二值化,那样的话就会比这个更精细。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/12433020.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-25
下一篇 2023-05-25

发表评论

登录后才能评论

评论列表(0条)

保存