{"rsdb":{"rid":"239654","subhead":"","postdate":"0","aid":"165145","fid":"49","uid":"1","topic":"1","content":"
\n

\u7528C++<\/a>\u5b9e\u73b0\u8fdb\u7a0b\u540c\u6b65\uff0c\u8fdb\u7a0b\u95f4\u5171\u4eab\u5185\u5b58<\/h3> \n
\r\n\/\/ \u4e00\uff0c\u8bfb\u5171\u4eab\u5185\u5b58\u6e90\u4ee3\u7801\r\n\/\/ \/\/ShareMemory_Read.cpp : \u5b9a\u4e49\u63a7\u5236\u53f0\u5e94\u7528\u7a0b\u5e8f\u7684\u5165\u53e3\u70b9\u3002\r\n**\u91cd\u70b9\u5185\u5bb9**\r\n#include "stdafx.h"\r\n#include "cv.h"\r\n#include "cxcore.h"\r\n#include "highgui.h"\r\n#include \n  \n   \r\n#include "opencv2\/opencv.hpp"\r\n#include "opencv2\/highgui\/highgui.hpp"\r\n#include \n   \n     #include "afxwin.h" \/\/=========\u4e92\u65a5\u91cf========================================== #include "stdafx.h" #include\n    \n      #include\n     \n       #include\n      \n        char name[100] = "BeiJing-LingYun"; \/\/=========\u4e92\u65a5\u91cf========================================== using namespace cv; using namespace std; #define BUF_SIZE 5038849 int ImgSaveIndex=0; int main() { \/\/ \u6253\u5f00\u5171\u4eab\u7684\u6587\u4ef6\u5bf9\u8c61 while (true) { \/\/------------\u4e92\u65a5\u91cf------------------------------------------------------------------- HANDLE mutex = OpenMutex(MUTEX_ALL_ACCESS, TRUE, name); if (mutex == NULL) { \/\/ printf("\u6253\u5f00\u5931\u8d25\\n"); } else { int a=0; } \/\/printf("\u7b49\u5f85......\\n"); DWORD res = WaitForSingleObject(mutex, 20000); switch (res) { case WAIT_OBJECT_0: { printf("\u6536\u5230\u4fe1\u53f7......\\n"); \/\/-------------\u56fe\u50cf\u5904\u7406----------------------------------------------------------------- HANDLE hMapFile = OpenFileMapping(FILE_MAP_ALL_ACCESS,NULL,"ShareMemory"); if (hMapFile) { LPVOID lpBase = MapViewOfFile(hMapFile,FILE_MAP_ALL_ACCESS,0,0,0); \/\/ \u5c06\u5171\u4eab\u5185\u5b58\u6570\u636e\u62f7\u8d1d\u51fa\u6765 \/\/char szBuffer[BUF_SIZE] = {0}; char *szBuffer= new char[BUF_SIZE]; strcpy(szBuffer,(char*)lpBase); \/\/\/\/----------------\u5b58\u50a8\u56fe\u50cf--------------------------------------- Mat MImg; MImg=cv::Mat(1944, 2592,CV_8UC1); memcpy(MImg.data,szBuffer,2592*1944); ImgSaveIndex++; char ch_sf[20]; itoa(ImgSaveIndex,ch_sf,10); string strSaveImageTempPath; string strSavePath="D:\\\\JD_ImageAcq\\\\"; strSaveImageTempPath=strSavePath+ch_sf; \/\/\u5b58\u50a8\u6821\u6b63\u56fe string strCalibateImg=strSaveImageTempPath+"_\u6821\u6b63.bmp"; imwrite(strCalibateImg,MImg); \/\/\u5b58\u50a8\u77eb\u6b63\u56fe \/\/----------------\u5b58\u50a8\u56fe\u50cf--------------------------------------- \/\/printf("%s",szBuffer); \/\/ \u89e3\u9664\u6587\u4ef6\u6620\u5c04 UnmapViewOfFile(lpBase); \/\/ \u5173\u95ed\u5185\u5b58\u6620\u5c04\u6587\u4ef6\u5bf9\u8c61\u53e5\u67c4 CloseHandle(hMapFile); } else { \/\/ \u6253\u5f00\u5171\u4eab\u5185\u5b58\u53e5\u67c4\u5931\u8d25 printf("OpenMapping Error\\n"); \/\/Sleep(2000); } } \/\/-------------\u56fe\u50cf\u5904\u7406----------------------------------------------------------------- break; case WAIT_TIMEOUT: printf("\u8d85\u65f6\u6ca1\u6709\u6536\u5230.....\\n"); break; case WAIT_ABANDONED: printf("\u53e6\u4e00\u4e2a\u8fdb\u7a0b\u610f\u5916\u7ec8\u6b62...\\n"); break; default : break; } \/\/\u4e00\u65e6\u4e0d\u518d\u9700\u8981\uff0c\u6ce8\u610f\u4e00\u5b9a\u8981\u7528 CloseHandle \u5173\u95ed\u4e92\u65a5\u4f53\u53e5\u67c4\u3002\u5982\u5bf9\u8c61\u7684\u6240\u6709\u53e5\u67c4\u90fd\u5df2\u5173\u95ed\uff0c\u90a3\u4e48\u5bf9\u8c61\u4e5f\u4f1a\u5220\u9664 CloseHandle(mutex); \/\/------------\u4e92\u65a5\u91cf------------------------------------------------------------------- } system("pause"); return 0; } \n      <\/windows.h>\n     <\/stdlib.h>\n    <\/stdio.h>\n   <\/iostream>\n  <\/stdlib.h><\/pre> \n 

\/\/\u4e8c\uff0c\u521b\u5efa\u5171\u4eab\u5185\u5b58\u6e90\u4ee3\u7801\uff1a<\/p> \n

\r\n    \/\/---------------\u5171\u4eab\u5185\u5b58------------------------------------------------------------------------\r\n                \/\/ \u5b9a\u4e49\u5171\u4eab\u6570\u636e\r\n                cvtColor(MCorrectedImg, MCorrectedImg, COLOR_BGR2GRAY);        \/\/\u8f6c\u6362\u6210\u7070\u5ea6\u56fe\r\n\r\n                int channels = MCorrectedImg.channels();\r\n                int nRows = MCorrectedImg.rows;             \/\/\u884c\r\n                int nCols = MCorrectedImg.cols* channels;   \/\/\u5217\r\n\r\n                pDlg->m_pShareDate = new char[nRows * nCols * channels];\r\n                bool bb=pDlg->MatToChar(MCorrectedImg,pDlg->m_pShareDate);\r\n\r\n\r\n                LPVOID lpBase;\r\n                HANDLE hMapFile;\r\n                if (bb==true)\r\n                {\r\n                    \/\/ \u521b\u5efa\u5171\u4eab\u6587\u4ef6\u53e5\u67c4 \r\n                    hMapFile = CreateFileMapping(\r\n                                 INVALID_HANDLE_VALUE,   \/\/ \u7269\u7406\u6587\u4ef6\u53e5\u67c4\r\n                        NULL,   \/\/ \u9ed8\u8ba4\u5b89\u5168\u7ea7\u522b\r\n                        PAGE_READWRITE,   \/\/ \u53ef\u8bfb\u53ef\u5199\r\n","orderid":"0","title":"\u7528C++\u5b9e\u73b0\u8fdb\u7a0b\u540c\u6b65\uff0c\u8fdb\u7a0b\u95f4\u5171\u4eab\u5185\u5b58(\u4e00)","smalltitle":"","mid":"0","fname":"c++\u7f16\u7a0b\u57fa\u7840","special_id":"0","bak_id":"0","info":"0","hits":"9492","pages":"2","comments":"0","posttime":"2017-10-18 09:07:21","list":"1508288841","username":"admin","author":"","copyfrom":"","copyfromurl":"","titlecolor":"","fonttype":"0","titleicon":"0","picurl":"https:\/\/www.cppentry.com\/upload_files\/","ispic":"0","yz":"1","yzer":"","yztime":"0","levels":"0","levelstime":"0","keywords":"\u5b9e\u73b0<\/A> \u8fdb\u7a0b<\/A> \u540c\u6b65<\/A> \u5171\u4eab<\/A> \u5185\u5b58<\/A>","jumpurl":"","iframeurl":"","style":"","template":"a:3:{s:4:\"head\";s:0:\"\";s:4:\"foot\";s:0:\"\";s:8:\"bencandy\";s:0:\"\";}","target":"0","ip":"113.108.110.181","lastfid":"0","money":"0","buyuser":"","passwd":"","allowdown":"","allowview":"","editer":"","edittime":"0","begintime":"0","endtime":"0","description":"\u7528C++\u5b9e\u73b0\u8fdb\u7a0b\u540c\u6b65\uff0c\u8fdb\u7a0b\u95f4\u5171\u4eab\u5185\u5b58","lastview":"1713481924","digg_num":"4798","digg_time":"1713304138","forbidcomment":"0","ifvote":"0","heart":"","htmlname":"","city_id":"0"},"page":"1"}