1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
| ```` #include <iostream> #include <string> #include <vector> #include <thread> #include "time.h" #include "opencv2/opencv.hpp" #include "stdio.h" #include "GxIAPI.h"
cv::Mat empty(1024, 1280, CV_8UC3, cv::Scalar::all(0)); timeval tv; long time_end; long time_start;
static void GX_STDC OnFrameCallbackFun(GX_FRAME_CALLBACK_PARAM *pFrame) { if (pFrame->status == 0) { gettimeofday(&tv, NULL); time_end = tv.tv_sec * 1000000 + tv.tv_usec; std::cout << 1000000 / (time_end - time_start) << "fps" << "get an image" << std::endl; time_start = time_end; void *rgb_buffer = malloc(3 * pFrame->nImgSize); DxRaw8toRGB24((void *)pFrame->pImgBuf, rgb_buffer, pFrame->nWidth, pFrame->nHeight, RAW2RGB_NEIGHBOUR, BAYERRG, false); cv::Mat result = cv::Mat(pFrame->nHeight, pFrame->nWidth, CV_8UC3, rgb_buffer); result.copyTo(empty); } else { std::cout << "fuck,trigger is failed" << std::endl; } return; }
int main(int argc, char *argv[]) { GX_STATUS status = GX_STATUS_SUCCESS; GX_DEV_HANDLE hDevice = NULL; GX_OPEN_PARAM stOpenParam; uint32_t nDeviceNum = 0; gettimeofday(&tv, NULL); time_end = tv.tv_sec * 1000000 + tv.tv_usec; time_start = tv.tv_sec * 1000000 + tv.tv_usec; status = GXInitLib(); status = GXUpdateDeviceList(&nDeviceNum, 1000); if ((status != GX_STATUS_SUCCESS) || (nDeviceNum <= 0)) { return 0; } stOpenParam.accessMode = GX_ACCESS_EXCLUSIVE; stOpenParam.openMode = GX_OPEN_INDEX; stOpenParam.pszContent = "1"; status = GXOpenDevice(&stOpenParam, &hDevice); if (status == GX_STATUS_SUCCESS) { status = GXSetEnum(hDevice, GX_ENUM_TRIGGER_MODE, GX_TRIGGER_MODE_ON); status = GXSetEnum(hDevice, GX_ENUM_TRIGGER_ACTIVATION, GX_TRIGGER_ACTIVATION_RISINGEDGE); status = GXSetEnum(hDevice, GX_ENUM_TRIGGER_SOURCE, GX_TRIGGER_SOURCE_LINE2); status = GXSetEnum(hDevice, GX_ENUM_LINE_SELECTOR, GX_ENUM_LINE_SELECTOR_LINE2); status = GXSetEnum(hDevice, GX_ENUM_LINE_MODE, GX_ENUM_LINE_MODE_INPUT);
status = GXSetFloat(hDevice, GX_FLOAT_EXPOSURE_TIME, (float)3000); status = GXSetEnum(hDevice, GX_ENUM_BALANCE_RATIO_SELECTOR, GX_BALANCE_RATIO_SELECTOR_RED); status = GXSetFloat(hDevice, GX_FLOAT_BALANCE_RATIO, 1.6484); status = GXSetEnum(hDevice, GX_ENUM_BALANCE_RATIO_SELECTOR, GX_BALANCE_RATIO_SELECTOR_BLUE); status = GXSetFloat(hDevice, GX_FLOAT_BALANCE_RATIO, 1.5664); status = GXSetEnum(hDevice, GX_ENUM_BALANCE_RATIO_SELECTOR, GX_BALANCE_RATIO_SELECTOR_GREEN); status = GXSetFloat(hDevice, GX_FLOAT_BALANCE_RATIO, 1.000); status = GXSetEnum(hDevice, GX_ENUM_GAIN_SELECTOR, GX_GAIN_SELECTOR_ALL); status = GXSetFloat(hDevice, GX_FLOAT_GAIN, 10.0); status = GXRegisterCaptureCallback(hDevice, NULL, OnFrameCallbackFun); status = GXSendCommand(hDevice, GX_COMMAND_ACQUISITION_START); } int64_t nAllLineStatus = 0; while (1) { cv::imshow("test", empty); if (cv::waitKey(1) == 'a') { } if (cv::waitKey(1) == 'b') { GX_STATUS Status = GXGetInt(hDevice, GX_INT_LINE_STATUS_ALL, &nAllLineStatus); std::cout << "line status:" << nAllLineStatus << std::endl; } if (cv::waitKey(1) == 'q') { status = GXSendCommand(hDevice, GX_COMMAND_ACQUISITION_STOP); status = GXUnregisterCaptureCallback(hDevice); status = GXCloseDevice(hDevice); hDevice = NULL; status = GXCloseLib(); std::cout << "end captrue" << std::endl; return 0; } } }
|