将这里的图片传给opencv,在opencv下进行分析和处理。
实验思路:
1 创造指针。指向图像
- #include <cv.h>
- #include <highgui.h>
- using namespace cv;
-
- int fnCameraCheckA(unsigned char* imageData, int width, int height, int * result);
-
- int main(int argc, char** argv)
- {
- if (argc != 1) // 要求函数不带参数,带参数则报错。
- {
- printf("useage: %s <imagefile>\n ", argv[0]);
- return -1;
- }
- //char* imageName = argv[1];
-
- //读图片,并转换为灰度图像
- char* imageName = "12B.bmp";
- Mat image;
- image = imread(imageName, CV_LOAD_IMAGE_COLOR);
- cvtColor(image, image, CV_BGR2GRAY);
- int width, height,step;
- int a = -1;
- int *result1 = &a ; //int* result 进行结果传递的指针;
- width = image.cols; // 列数
- height = image.rows; // 行数
- unsigned char* imageData = image.data; // 数据
- if (!image.data)
- {
- printf(" No image data \n ");
- return -1;
- }
-
- // 利用传递过来的图像指针和行列参数,生成能被openCV处理的Mat格式图像数据。
- fnCameraCheckA(imageData, width, height, result1);
- if (*result1 == 1)
- {
- printf(" 图像传递successful!!");
- }
-
- waitKey(0);
- return 0;
- }
2传递给函数进行,并显示图像。
- int fnCameraCheckA(unsigned char* imageData, int width, int height, int *result1)
- {
- Mat img(height, width, CV_8U, imageData); //CV_8U:8位无符号单一通道。
- if (!img.data)
- {
- printf(" No image data \n ");
- return -1;
- }
- imshow("传递过来的图像", img);
- *result1 = 1;
- return 1;
- }
3 返回结果。
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。