#include #include #include #pragma comment(lib,"cv.lib") #pragma comment(lib,"cxcore.lib") #pragma comment(lib,"highgui.lib") void rectangle(unsigned char *img, int height, int width, int channel, int xStart, int xEnd, int yStart, int yEnd, int large, int red, int blue, int green); int main(){ IplImage *img; img = cvLoadImage("./image.bmp", 1); rectangle((unsigned char*)img->imageData, img->height, img->width, img->nChannels, 5, 500, 100, 200, 5, 255, 0, 0); cvNamedWindow("img", 1); cvShowImage("img", img); cvWaitKey(-1); cvDestroyWindow("img"); cvReleaseImage(&img); return 0; } /* in : ‰¡‚Í4ƒoƒCƒg */ void rectangle(unsigned char *img, int height, int width, int channel, int xStart, int xEnd, int yStart, int yEnd, int large, int red, int blue, int green){ int i, j; int widthStep; widthStep = width * channel; if( (widthStep % 4) != 0){ widthStep = widthStep + 4 - widthStep%4; } for(i = yStart; i <= yEnd; ++i){ for(j = 0; j < large; ++j){ img[i * widthStep + (xStart + j) * 3] = blue; img[i * widthStep + (xStart + j) * 3 + 1] = green; img[i * widthStep + (xStart + j) * 3 + 2] = red; img[i * widthStep + (xEnd - j) * 3] = blue; img[i * widthStep + (xEnd - j) * 3 + 1] = green; img[i * widthStep + (xEnd - j) * 3 + 2] = red; } } for(j = xStart; j <= xEnd; ++j){ for(i = 0; i < large; ++i){ img[(yStart + i) * widthStep + j * 3] = blue; img[(yStart + i) * widthStep + j * 3 + 1] = green; img[(yStart + i) * widthStep + j * 3 + 2] = red; img[(yEnd - i) * widthStep + j * 3] = blue; img[(yEnd - i) * widthStep + j * 3 + 1] = green; img[(yEnd - i) * widthStep + j * 3 + 2] = red; } } }