深度颜色1

来源:互联网 发布:假面骑士wizard知乎 编辑:程序博客网 时间:2024/06/06 08:52
// depth_color.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include <windows.h>  #include <iostream>   #include <NuiApi.h>  #include <opencv2/opencv.hpp>  using namespace std;using namespace cv;static float Depth_value;//bool tracked[NUI_SKELETON_COUNT] = { FALSE };//CvPoint skeletonPoint[NUI_SKELETON_COUNT][NUI_SKELETON_POSITION_COUNT] = { cvPoint(0,0) };//CvPoint colorPoint[NUI_SKELETON_COUNT][NUI_SKELETON_POSITION_COUNT] = { cvPoint(0,0) };void getColorImage(HANDLE &colorEvent, HANDLE &colorStreamHandle, Mat &colorImage);void getDepthImage(HANDLE &depthEvent, HANDLE &depthStreamHandle, Mat &depthImage);//void getSkeletonImage(HANDLE &skeletonEvent, Mat &skeletonImage, Mat &colorImage, Mat &depthImage);//void drawSkeleton(Mat &image, CvPoint pointSet[], int witchone);//void getTheContour(Mat &image, int whichone, Mat &mask);int main(int argc, char *argv[]){Mat colorImage;colorImage.create(480, 640, CV_8UC3);Mat depthImage;depthImage.create(480, 640, CV_8UC1);//Mat skeletonImage;//skeletonImage.create(240, 320, CV_8UC3);//Mat mask;//mask.create(240, 320, CV_8UC3);HANDLE colorEvent = CreateEvent(NULL, TRUE, FALSE, NULL);HANDLE depthEvent = CreateEvent(NULL, TRUE, FALSE, NULL);//HANDLE skeletonEvent = CreateEvent(NULL, TRUE, FALSE, NULL);HANDLE colorStreamHandle = NULL;HANDLE depthStreamHandle = NULL;HRESULT hr = NuiInitialize(NUI_INITIALIZE_FLAG_USES_COLOR | NUI_INITIALIZE_FLAG_USES_DEPTH);if (hr != S_OK){cout << "NuiInitialize failed" << endl;return hr;}hr = NuiImageStreamOpen(NUI_IMAGE_TYPE_COLOR, NUI_IMAGE_RESOLUTION_640x480, NULL, 4, colorEvent, &colorStreamHandle);if (hr != S_OK){cout << "Open the color Stream failed" << endl;NuiShutdown();return hr;}hr = NuiImageStreamOpen(NUI_IMAGE_TYPE_DEPTH, NUI_IMAGE_RESOLUTION_640x480, NULL, 2, depthEvent, &depthStreamHandle);if (hr != S_OK){cout << "Open the depth Stream failed" << endl;NuiShutdown();return hr;}/*hr = NuiSkeletonTrackingEnable(skeletonEvent, 0);//打开骨骼跟踪事件     if (hr != S_OK){cout << "NuiSkeletonTrackingEnable failed" << endl;NuiShutdown();return hr;}*///namedWindow("mask", CV_WINDOW_AUTOSIZE);namedWindow("colorImage", CV_WINDOW_AUTOSIZE);//namedWindow("depthImage", CV_WINDOW_AUTOSIZE);//namedWindow("skeletonImage", CV_WINDOW_AUTOSIZE);while (1){if (WaitForSingleObject(colorEvent, 0) == 0){getColorImage(colorEvent, colorStreamHandle, colorImage);}if (WaitForSingleObject(depthEvent, 0) == 0){getDepthImage(depthEvent, depthStreamHandle, depthImage);}//这里使用INFINITE是为了避免没有激活skeletonEvent而跳过此代码出现colorimage频闪的现象   /*if (WaitForSingleObject(skeletonEvent, INFINITE) == 0)getSkeletonImage(skeletonEvent, skeletonImage, colorImage, depthImage);*//*for (int i = 0; i<6; i++){if (tracked[i] == TRUE){mask.setTo(0);getTheContour(depthImage, i, mask);tracked[i] = FALSE;break;}}*///imshow("mask", mask);imshow("colorImage", colorImage);//imshow("depthImage", depthImage);//imshow("skeletonImage", skeletonImage);if (cvWaitKey(1) == 27)break;}NuiShutdown();return 0;}void getColorImage(HANDLE &colorEvent, HANDLE &colorStreamHandle, Mat &colorImage){const NUI_IMAGE_FRAME *colorFrame = NULL;NuiImageStreamGetNextFrame(colorStreamHandle, 0, &colorFrame);INuiFrameTexture *pTexture = colorFrame->pFrameTexture;NUI_LOCKED_RECT LockedRect;pTexture->LockRect(0, &LockedRect, NULL, 0);if (LockedRect.Pitch != 0){for (int i = 0; i<colorImage.rows; i++){uchar *ptr = colorImage.ptr<uchar>(i);  //第i行的指针                    //每个字节代表一个颜色信息,直接使用uchar  uchar *pBuffer = (uchar*)(LockedRect.pBits) + i * LockedRect.Pitch;for (int j = 0; j<colorImage.cols; j++){ptr[3 * j] = pBuffer[4 * j];  //内部数据是4个字节,0-1-2是BGR,第4个现在未使用   ptr[3 * j + 1] = pBuffer[4 * j + 1];ptr[3 * j + 2] = pBuffer[4 * j + 2];}}Point center = Point(colorImage.cols/2, colorImage.rows/2);int r = 1;circle(colorImage, center, r, Scalar(255, 255, 255));char output[100] = { 0 };char p[100] = { 0 };sprintf_s(p, "Height");char m[100] = { 0 };sprintf_s(m, "Distance");char t[100] = { 0 };sprintf_s(t, "Gesture");sprintf_s(output, "C:\\Users\\Administrator\\Desktop\\kinect\\%s_%d_%s_%d_%s_%d.jpg",p,1,m,1,t,1);imwrite(output, colorImage);//rectangle(colorImage, Point(colorImage.rows / 2 - 1, colorImage.cols / 2 - 1), Point(colorImage.rows / 2 + 1, colorImage.cols / 2 + 1), Scalar(255, 255, 255));}else{cout << "捕捉色彩图像出现错误" << endl;}pTexture->UnlockRect(0);NuiImageStreamReleaseFrame(colorStreamHandle, colorFrame);}void getDepthImage(HANDLE &depthEvent, HANDLE &depthStreamHandle, Mat &depthImage){const NUI_IMAGE_FRAME *depthFrame = NULL;NuiImageStreamGetNextFrame(depthStreamHandle, 0, &depthFrame);INuiFrameTexture *pTexture = depthFrame->pFrameTexture;NUI_LOCKED_RECT LockedRect;pTexture->LockRect(0, &LockedRect, NULL, 0);if (LockedRect.Pitch != 0){for (int i = 0; i<depthImage.rows; i++){uchar *ptr = depthImage.ptr<uchar>(i);uchar *pBufferRun = (uchar*)(LockedRect.pBits) + i * LockedRect.Pitch;USHORT *pBuffer = (USHORT*)pBufferRun;for (int j = 0; j<depthImage.cols; j++){if (i == 240){//stringstream depth_value;//depth_value << (float)pBuffer[depthImage.cols / 2] / 0x7fff * 0x0fff;//cout << ((float)pBuffer[depthImage.cols / 2]*0.123138 +162.7355 )<< endl;// / 0x7fff * 0x0fffDepth_value = ((float)pBuffer[depthImage.cols / 2] * 0.123138 + 162.7355);ptr[j] = (uchar)(256 * pBuffer[j] / 0x7fff);}else{ptr[j] = (uchar)(256 * pBuffer[j] / 0x7fff);  //直接将数据归一化处理} }}//imshow("depthImage", depthImage);Mat img_pseudocolor(depthImage.rows, depthImage.cols, CV_8UC3);//构造RGB图像,参数CV_8UC3教程文档里面有讲解  int tmp = 0;for (int y = 0; y<depthImage.rows; y++)//转为伪彩色图像的具体算法  {for (int x = 0; x<depthImage.cols; x++){double L = 256;tmp = depthImage.at<unsigned char>(y, x);if (tmp < L / 4){img_pseudocolor.at<Vec3b>(y, x)[0] = L; //blue  img_pseudocolor.at<Vec3b>(y, x)[1] = 0; //green  img_pseudocolor.at<Vec3b>(y, x)[2] = 4 * tmp; //red  }else if (tmp < L / 2){img_pseudocolor.at<Vec3b>(y, x)[0] = L; //blue  img_pseudocolor.at<Vec3b>(y, x)[1] = 4 * (L / 2 - tmp); //green  img_pseudocolor.at<Vec3b>(y, x)[2] = 0; //red  }else if (tmp < 3 * L / 4){img_pseudocolor.at<Vec3b>(y, x)[0] = 4 * (L / 2 - tmp); //blue  img_pseudocolor.at<Vec3b>(y, x)[1] = 0; //green  img_pseudocolor.at<Vec3b>(y, x)[2] = L; //red  }else{img_pseudocolor.at<Vec3b>(y, x)[0] = 0; //blue  img_pseudocolor.at<Vec3b>(y, x)[1] = 4 * (L - tmp); //green  img_pseudocolor.at<Vec3b>(y, x)[2] = L; //red }}}/*for (int y = 0; y<image.rows; y++)//转为伪彩色图像的具体算法{for (int x = 0; x<image.cols; x++){tmp = image.at<unsigned char>(y, x);img_pseudocolor.at<Vec3b>(y, x)[0] = abs(255 - tmp); //blueimg_pseudocolor.at<Vec3b>(y, x)[1] = abs(127 - tmp); //greenimg_pseudocolor.at<Vec3b>(y, x)[2] = abs(0 - tmp); //red}}*/namedWindow("img_pseudocolor");Point center = Point(img_pseudocolor.cols / 2, 240);int r = 1;circle(img_pseudocolor,center, r, Scalar(255, 255, 255));//rectangle(img_pseudocolor, Point(img_pseudocolor.rows / 2 - 1, img_pseudocolor.cols / 2 - 1), Point(img_pseudocolor.rows / 2 + 1, img_pseudocolor.cols / 2 + 1), Scalar(255, 255, 255));//string img_depth;//img_depth += image.at<unsigned char>(image.rows / 2, image.cols / 2);//string s;//sprintf(s, depthImage.at<unsigned char>(depthImage.rows / 2, depthImage.cols / 2));//float img_depth = depthImage.at<unsigned char>(depthImage.rows / 2, depthImage.cols / 2);//cout << img_depth / 256 * 0x0fff << endl;stringstream depth_value;depth_value << Depth_value;putText(img_pseudocolor,depth_value.str(), center, CV_FONT_HERSHEY_COMPLEX,1,Scalar(255,255,255));imshow("img_pseudocolor", img_pseudocolor);char output[100] = { 0 };char p[100] = { 0 };sprintf_s(p, "Height");char m[100] = { 0 };sprintf_s(m, "Distance");char t[100] = { 0 };sprintf_s(t, "Gesture");sprintf_s(output, "C:\\Users\\Administrator\\Desktop\\kinect\\%s_%d_%s_%d_%s_%d_%d.jpg",p,1,m,1,t,1,1);imwrite(output, img_pseudocolor);}else{cout << "捕捉深度图像出现错误" << endl;}pTexture->UnlockRect(0);NuiImageStreamReleaseFrame(depthStreamHandle, depthFrame);}/*void getSkeletonImage(HANDLE &skeletonEvent, Mat &skeletonImage, Mat &colorImage, Mat &depthImage){NUI_SKELETON_FRAME skeletonFrame = { 0 };bool bFoundSkeleton = false;if (NuiSkeletonGetNextFrame(0, &skeletonFrame) == S_OK){for (int i = 0; i < NUI_SKELETON_COUNT; i++){if (skeletonFrame.SkeletonData[i].eTrackingState == NUI_SKELETON_TRACKED){bFoundSkeleton = true;break;}}}else{cout << "没有找到合适的骨骼帧" << endl;return;}if (!bFoundSkeleton){return;}NuiTransformSmooth(&skeletonFrame, NULL);//平滑骨骼帧,消除抖动     skeletonImage.setTo(0);for (int i = 0; i < NUI_SKELETON_COUNT; i++){if (skeletonFrame.SkeletonData[i].eTrackingState == NUI_SKELETON_TRACKED &&skeletonFrame.SkeletonData[i].eSkeletonPositionTrackingState[NUI_SKELETON_POSITION_SHOULDER_CENTER] != NUI_SKELETON_POSITION_NOT_TRACKED){float fx, fy;for (int j = 0; j < NUI_SKELETON_POSITION_COUNT; j++)//所有的坐标转化为深度图的坐标     {NuiTransformSkeletonToDepthImage(skeletonFrame.SkeletonData[i].SkeletonPositions[j], &fx, &fy);skeletonPoint[i][j].x = (int)fx;skeletonPoint[i][j].y = (int)fy;}for (int j = 0; j<NUI_SKELETON_POSITION_COUNT; j++){if (skeletonFrame.SkeletonData[i].eSkeletonPositionTrackingState[j] != NUI_SKELETON_POSITION_NOT_TRACKED)//跟踪点一用有三种状态:1没有被跟踪到,2跟踪到,3根据跟踪到的估计到     {LONG colorx, colory;NuiImageGetColorPixelCoordinatesFromDepthPixel(NUI_IMAGE_RESOLUTION_640x480, 0,skeletonPoint[i][j].x, skeletonPoint[i][j].y, 0, &colorx, &colory);colorPoint[i][j].x = int(colorx);colorPoint[i][j].y = int(colory); //存储坐标点   circle(colorImage, colorPoint[i][j], 4, cvScalar(0, 255, 255), 1, 8, 0);circle(skeletonImage, skeletonPoint[i][j], 3, cvScalar(0, 255, 255), 1, 8, 0);tracked[i] = TRUE;}}drawSkeleton(colorImage, colorPoint[i], i);drawSkeleton(skeletonImage, skeletonPoint[i], i);}}}*//*void drawSkeleton(Mat &image, CvPoint pointSet[], int whichone){CvScalar color;switch (whichone) //跟踪不同的人显示不同的颜色   {case 0:color = cvScalar(255);break;case 1:color = cvScalar(0, 255);break;case 2:color = cvScalar(0, 0, 255);break;case 3:color = cvScalar(255, 255, 0);break;case 4:color = cvScalar(255, 0, 255);break;case 5:color = cvScalar(0, 255, 255);break;}if ((pointSet[NUI_SKELETON_POSITION_HEAD].x != 0 || pointSet[NUI_SKELETON_POSITION_HEAD].y != 0) &&(pointSet[NUI_SKELETON_POSITION_SHOULDER_CENTER].x != 0 || pointSet[NUI_SKELETON_POSITION_SHOULDER_CENTER].y != 0))line(image, pointSet[NUI_SKELETON_POSITION_HEAD], pointSet[NUI_SKELETON_POSITION_SHOULDER_CENTER], color, 2);if ((pointSet[NUI_SKELETON_POSITION_SHOULDER_CENTER].x != 0 || pointSet[NUI_SKELETON_POSITION_SHOULDER_CENTER].y != 0) &&(pointSet[NUI_SKELETON_POSITION_SPINE].x != 0 || pointSet[NUI_SKELETON_POSITION_SPINE].y != 0))line(image, pointSet[NUI_SKELETON_POSITION_SHOULDER_CENTER], pointSet[NUI_SKELETON_POSITION_SPINE], color, 2);if ((pointSet[NUI_SKELETON_POSITION_SPINE].x != 0 || pointSet[NUI_SKELETON_POSITION_SPINE].y != 0) &&(pointSet[NUI_SKELETON_POSITION_HIP_CENTER].x != 0 || pointSet[NUI_SKELETON_POSITION_HIP_CENTER].y != 0))line(image, pointSet[NUI_SKELETON_POSITION_SPINE], pointSet[NUI_SKELETON_POSITION_HIP_CENTER], color, 2);//左上肢   if ((pointSet[NUI_SKELETON_POSITION_SHOULDER_CENTER].x != 0 || pointSet[NUI_SKELETON_POSITION_SHOULDER_CENTER].y != 0) &&(pointSet[NUI_SKELETON_POSITION_SHOULDER_LEFT].x != 0 || pointSet[NUI_SKELETON_POSITION_SHOULDER_LEFT].y != 0))line(image, pointSet[NUI_SKELETON_POSITION_SHOULDER_CENTER], pointSet[NUI_SKELETON_POSITION_SHOULDER_LEFT], color, 2);if ((pointSet[NUI_SKELETON_POSITION_SHOULDER_LEFT].x != 0 || pointSet[NUI_SKELETON_POSITION_SHOULDER_LEFT].y != 0) &&(pointSet[NUI_SKELETON_POSITION_ELBOW_LEFT].x != 0 || pointSet[NUI_SKELETON_POSITION_ELBOW_LEFT].y != 0))line(image, pointSet[NUI_SKELETON_POSITION_SHOULDER_LEFT], pointSet[NUI_SKELETON_POSITION_ELBOW_LEFT], color, 2);if ((pointSet[NUI_SKELETON_POSITION_ELBOW_LEFT].x != 0 || pointSet[NUI_SKELETON_POSITION_ELBOW_LEFT].y != 0) &&(pointSet[NUI_SKELETON_POSITION_WRIST_LEFT].x != 0 || pointSet[NUI_SKELETON_POSITION_WRIST_LEFT].y != 0))line(image, pointSet[NUI_SKELETON_POSITION_ELBOW_LEFT], pointSet[NUI_SKELETON_POSITION_WRIST_LEFT], color, 2);if ((pointSet[NUI_SKELETON_POSITION_WRIST_LEFT].x != 0 || pointSet[NUI_SKELETON_POSITION_WRIST_LEFT].y != 0) &&(pointSet[NUI_SKELETON_POSITION_HAND_LEFT].x != 0 || pointSet[NUI_SKELETON_POSITION_HAND_LEFT].y != 0))line(image, pointSet[NUI_SKELETON_POSITION_WRIST_LEFT], pointSet[NUI_SKELETON_POSITION_HAND_LEFT], color, 2);//右上肢   if ((pointSet[NUI_SKELETON_POSITION_SHOULDER_CENTER].x != 0 || pointSet[NUI_SKELETON_POSITION_SHOULDER_CENTER].y != 0) &&(pointSet[NUI_SKELETON_POSITION_SHOULDER_RIGHT].x != 0 || pointSet[NUI_SKELETON_POSITION_SHOULDER_RIGHT].y != 0))line(image, pointSet[NUI_SKELETON_POSITION_SHOULDER_CENTER], pointSet[NUI_SKELETON_POSITION_SHOULDER_RIGHT], color, 2);if ((pointSet[NUI_SKELETON_POSITION_SHOULDER_RIGHT].x != 0 || pointSet[NUI_SKELETON_POSITION_SHOULDER_RIGHT].y != 0) &&(pointSet[NUI_SKELETON_POSITION_ELBOW_RIGHT].x != 0 || pointSet[NUI_SKELETON_POSITION_ELBOW_RIGHT].y != 0))line(image, pointSet[NUI_SKELETON_POSITION_SHOULDER_RIGHT], pointSet[NUI_SKELETON_POSITION_ELBOW_RIGHT], color, 2);if ((pointSet[NUI_SKELETON_POSITION_ELBOW_RIGHT].x != 0 || pointSet[NUI_SKELETON_POSITION_ELBOW_RIGHT].y != 0) &&(pointSet[NUI_SKELETON_POSITION_WRIST_RIGHT].x != 0 || pointSet[NUI_SKELETON_POSITION_WRIST_RIGHT].y != 0))line(image, pointSet[NUI_SKELETON_POSITION_ELBOW_RIGHT], pointSet[NUI_SKELETON_POSITION_WRIST_RIGHT], color, 2);if ((pointSet[NUI_SKELETON_POSITION_WRIST_RIGHT].x != 0 || pointSet[NUI_SKELETON_POSITION_WRIST_RIGHT].y != 0) &&(pointSet[NUI_SKELETON_POSITION_HAND_RIGHT].x != 0 || pointSet[NUI_SKELETON_POSITION_HAND_RIGHT].y != 0))line(image, pointSet[NUI_SKELETON_POSITION_WRIST_RIGHT], pointSet[NUI_SKELETON_POSITION_HAND_RIGHT], color, 2);//左下肢   if ((pointSet[NUI_SKELETON_POSITION_HIP_CENTER].x != 0 || pointSet[NUI_SKELETON_POSITION_HIP_CENTER].y != 0) &&(pointSet[NUI_SKELETON_POSITION_HIP_LEFT].x != 0 || pointSet[NUI_SKELETON_POSITION_HIP_LEFT].y != 0))line(image, pointSet[NUI_SKELETON_POSITION_HIP_CENTER], pointSet[NUI_SKELETON_POSITION_HIP_LEFT], color, 2);if ((pointSet[NUI_SKELETON_POSITION_HIP_LEFT].x != 0 || pointSet[NUI_SKELETON_POSITION_HIP_LEFT].y != 0) &&(pointSet[NUI_SKELETON_POSITION_KNEE_LEFT].x != 0 || pointSet[NUI_SKELETON_POSITION_KNEE_LEFT].y != 0))line(image, pointSet[NUI_SKELETON_POSITION_HIP_LEFT], pointSet[NUI_SKELETON_POSITION_KNEE_LEFT], color, 2);if ((pointSet[NUI_SKELETON_POSITION_KNEE_LEFT].x != 0 || pointSet[NUI_SKELETON_POSITION_KNEE_LEFT].y != 0) &&(pointSet[NUI_SKELETON_POSITION_ANKLE_LEFT].x != 0 || pointSet[NUI_SKELETON_POSITION_ANKLE_LEFT].y != 0))line(image, pointSet[NUI_SKELETON_POSITION_KNEE_LEFT], pointSet[NUI_SKELETON_POSITION_ANKLE_LEFT], color, 2);if ((pointSet[NUI_SKELETON_POSITION_ANKLE_LEFT].x != 0 || pointSet[NUI_SKELETON_POSITION_ANKLE_LEFT].y != 0) &&(pointSet[NUI_SKELETON_POSITION_FOOT_LEFT].x != 0 || pointSet[NUI_SKELETON_POSITION_FOOT_LEFT].y != 0))line(image, pointSet[NUI_SKELETON_POSITION_ANKLE_LEFT], pointSet[NUI_SKELETON_POSITION_FOOT_LEFT], color, 2);//右下肢   if ((pointSet[NUI_SKELETON_POSITION_HIP_CENTER].x != 0 || pointSet[NUI_SKELETON_POSITION_HIP_CENTER].y != 0) &&(pointSet[NUI_SKELETON_POSITION_HIP_RIGHT].x != 0 || pointSet[NUI_SKELETON_POSITION_HIP_RIGHT].y != 0))line(image, pointSet[NUI_SKELETON_POSITION_HIP_CENTER], pointSet[NUI_SKELETON_POSITION_HIP_RIGHT], color, 2);if ((pointSet[NUI_SKELETON_POSITION_HIP_RIGHT].x != 0 || pointSet[NUI_SKELETON_POSITION_HIP_RIGHT].y != 0) &&(pointSet[NUI_SKELETON_POSITION_KNEE_RIGHT].x != 0 || pointSet[NUI_SKELETON_POSITION_KNEE_RIGHT].y != 0))line(image, pointSet[NUI_SKELETON_POSITION_HIP_RIGHT], pointSet[NUI_SKELETON_POSITION_KNEE_RIGHT], color, 2);if ((pointSet[NUI_SKELETON_POSITION_KNEE_RIGHT].x != 0 || pointSet[NUI_SKELETON_POSITION_KNEE_RIGHT].y != 0) &&(pointSet[NUI_SKELETON_POSITION_ANKLE_RIGHT].x != 0 || pointSet[NUI_SKELETON_POSITION_ANKLE_RIGHT].y != 0))line(image, pointSet[NUI_SKELETON_POSITION_KNEE_RIGHT], pointSet[NUI_SKELETON_POSITION_ANKLE_RIGHT], color, 2);if ((pointSet[NUI_SKELETON_POSITION_ANKLE_RIGHT].x != 0 || pointSet[NUI_SKELETON_POSITION_ANKLE_RIGHT].y != 0) &&(pointSet[NUI_SKELETON_POSITION_FOOT_RIGHT].x != 0 || pointSet[NUI_SKELETON_POSITION_FOOT_RIGHT].y != 0))line(image, pointSet[NUI_SKELETON_POSITION_ANKLE_RIGHT], pointSet[NUI_SKELETON_POSITION_FOOT_RIGHT], color, 2);}*///根据给定的深度数据的关系(在getDepthImage()中的)确定不同的跟踪目标   /*void getTheContour(Mat &image, int whichone, Mat &mask){for (int i = 0; i<image.rows; i++){uchar *ptr = image.ptr<uchar>(i);uchar *ptrmask = mask.ptr<uchar>(i);for (int j = 0; j<image.cols; j++){if (ptr[3 * j] == 0 && ptr[3 * j + 1] == 0 && ptr[3 * j + 2] == 0) //都为0的时候予以忽略   {ptrmask[3 * j] = ptrmask[3 * j + 1] = ptrmask[3 * j + 2] = 0;}else if (ptr[3 * j] == 0 && ptr[3 * j + 1] == 0 && ptr[3 * j + 2] != 0)//ID为1的时候,显示绿色   {ptrmask[3 * j] = 0;ptrmask[3 * j + 1] = 255;ptrmask[3 * j + 2] = 0;}else if (ptr[3 * j] == 0 && ptr[3 * j + 1] != 0 && ptr[3 * j + 2] == 0)//ID为2的时候,显示红色   {ptrmask[3 * j] = 0;ptrmask[3 * j + 1] = 0;ptrmask[3 * j + 2] = 255;}else if (ptr[3 * j] == ptr[3 * j + 1] && ptr[3 * j] == 4 * ptr[3 * j + 2])//ID为3的时候   {ptrmask[3 * j] = 255;ptrmask[3 * j + 1] = 255;ptrmask[3 * j + 2] = 0;}else if (4 * ptr[3 * j] == ptr[3 * j + 1] && ptr[3 * j + 1] == ptr[3 * j + 2])//ID为4的时候   {ptrmask[3 * j] = 255;ptrmask[3 * j + 1] = 0;ptrmask[3 * j + 2] = 255;}else if (ptr[3 * j] == 4 * ptr[3 * j + 1] && ptr[3 * j] == ptr[3 * j + 2])//ID为5的时候   {ptrmask[3 * j] = 0;ptrmask[3 * j + 1] = 255;ptrmask[3 * j + 2] = 255;}else if (ptr[3 * j] == 2 * ptr[3 * j + 1] && ptr[3 * j + 1] == ptr[3 * j + 2])//ID为6的时候   {ptrmask[3 * j] = 255;ptrmask[3 * j + 1] = 255;ptrmask[3 * j + 2] = 255;}else if (ptr[3 * j] == ptr[3 * j + 1] && ptr[3 * j] == ptr[3 * j + 2])//ID为7的时候或者ID为0的时候,显示蓝色   {ptrmask[3 * j] = 255;ptrmask[3 * j + 1] = 0;ptrmask[3 * j + 2] = 0;}else{cout << "如果输出这段代码,说明有遗漏的情况,请查询getTheContour函数" << endl;}}}}*/