12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- // libimageproc.cpp : 定义 DLL 应用程序的导出函数。
- //
- #include "stdafx.h"
- #include "libimageproc.h"
- #include "highgui.h"
- #include "cv.h"
- #include "resource.h"
- LIBIMAGEPROC_API bool imageprocess(char* BackImgPath, char* FrontImgPath, char* ResultImgPath)
- {
- IplImage* pBK = cvLoadImage(BackImgPath, 1);
-
- IplImage* pfront = cvLoadImage(FrontImgPath, 1);
- if (pBK == NULL || pfront == NULL)
- return false;
- IplImage* pImg = cvCreateImage(cvSize(pfront->width, pfront->height), IPL_DEPTH_8U, 1);
- int j, i;
- CvMat bk;
- cvGetSubRect(pBK, &bk, cvRect(200, 30, pfront->width, pfront->height));
- cvCvtColor(pfront, pImg, CV_RGB2GRAY); //rgb转换为灰度图
- for (j = 0; j < pImg->height; j++)
- {
- uchar* ptr = (uchar*)(pImg->imageData + j * pImg->widthStep);
- uchar* ptr1 = (uchar*)(pfront->imageData + j * pfront->widthStep);
- uchar* ptr2 = (uchar*)(bk.data.ptr + j * bk.step);
- for (i = 0; i < pImg->width; i++)
- {
- if (ptr[i] < 220) //像素值小于220的保留下来 并显示到背景图上 即白色部分被去除
- {
- ptr2[i * 3] = ptr1[i * 3];
- ptr2[i * 3 + 1] = ptr1[i * 3 + 1];
- ptr2[i * 3 + 2] = ptr1[i * 3 + 2];
- }
- }
- }
- cvSaveImage(ResultImgPath, pBK);
- cvReleaseImage(&pBK);
- cvReleaseImage(&pfront);
- cvReleaseImage(&pImg);
- return true;
- }
|