| | |
| | | //获取平台 |
| | | error = clGetPlatformIDs(1, &platforms, &num_of_platforms); |
| | | if (error != 0) { |
| | | throw("Get platform failed!"); |
| | | throw string("Get platform failed!"); |
| | | } |
| | | //获取设备 |
| | | error = clGetDeviceIDs(platforms, CL_DEVICE_TYPE_GPU, 1, &devices, NULL); |
| | | if (error != 0) { |
| | | throw("Get device failed!"); |
| | | error = clGetDeviceIDs(platforms, CL_DEVICE_TYPE_CPU, 1, &devices, NULL); |
| | | if (error != 0) { |
| | | throw string("Get device failed!"); |
| | | } |
| | | } |
| | | |
| | | //创建上下文 |
| | | context = clCreateContext(NULL, 1, &devices, NULL, NULL, &error); |
| | | if (error != 0) { |
| | | throw("Creat context failed!"); |
| | | throw string("Creat context failed!"); |
| | | } |
| | | //创建程序;注意要用"rb" |
| | | fopen_s(&program_handle, "D:\\workspace\\CPlusTest\\ConsoleApplication\\ConsoleApplication\\kernel.cl", "rb"); |
| | | if (program_handle == NULL) { |
| | | throw("The kernle can not be opened!"); |
| | | throw string("The kernle can not be opened!"); |
| | | } |
| | | fseek(program_handle, 0, SEEK_END); |
| | | program_size = ftell(program_handle); |
| | |
| | | program_buffer[program_size] = '\0'; |
| | | error = fread(program_buffer, sizeof(char), program_size, program_handle); |
| | | if (error == 0) { |
| | | throw("Read kernel failed!"); |
| | | throw string("Read kernel failed!"); |
| | | } |
| | | fclose(program_handle); |
| | | program = clCreateProgramWithSource(context, 1, (const char**)&program_buffer, |
| | | &program_size, &error); |
| | | if (error < 0) { |
| | | throw("Couldn't create the program!"); |
| | | throw string("Couldn't create the program!"); |
| | | } |
| | | //编译程序 |
| | | error = clBuildProgram(program, 1, &devices, NULL, NULL, NULL); |
| | |
| | | log_size + 1, program_log, NULL); |
| | | printf("%s\n", program_log); |
| | | free(program_log); |
| | | throw("Build Program Failed"); |
| | | throw string("Build Program Failed"); |
| | | } |
| | | free(program_buffer); |
| | | |
| | | //创建命令队列 |
| | | queue = clCreateCommandQueue(context, devices, CL_QUEUE_PROFILING_ENABLE, &error); |
| | | if (error < 0) { |
| | | throw("Coudn't create the command queue"); |
| | | throw string("Coudn't create the command queue"); |
| | | } |
| | | } |
| | | |
| | |
| | | //创建内核 |
| | | kernel = clCreateKernel(program, "recognition_numbers_1", &error); |
| | | if (kernel == NULL) { |
| | | throw("Couldn't create kernel!\n"); |
| | | throw string("Couldn't create kernel!\n"); |
| | | } |
| | | //初始化参数 |
| | | unsigned char* result = (unsigned char*)malloc(sizeof(unsigned char) * resultSize); |
| | |
| | | //创建缓存对象 |
| | | cl_mem memObject1 = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(unsigned char) * inputSize, data, &error); |
| | | if (error < 0) { |
| | | throw("Creat memObject1 failed!\n"); |
| | | throw string("Creat memObject1 failed!\n"); |
| | | } |
| | | cl_mem memObject2 = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, |
| | | sizeof(unsigned char) * inputSize, b_in, &error); |
| | | if (error < 0) { |
| | | throw("Creat memObject2 failed!\n"); |
| | | throw string("Creat memObject2 failed!\n"); |
| | | } |
| | | |
| | | cl_mem memObject4 = clCreateBuffer(context, CL_MEM_WRITE_ONLY, |
| | | sizeof(unsigned char) * resultSize, NULL, &error); |
| | | if (error < 0) { |
| | | throw("Creat memObject4 failed!\n"); |
| | | throw string("Creat memObject4 failed!\n"); |
| | | } |
| | | |
| | | int width = cols / num_width; |
| | |
| | | error |= clSetKernelArg(kernel, 5, sizeof(int), &num_count); |
| | | error |= clSetKernelArg(kernel, 6, sizeof(cl_mem), &memObject4); |
| | | if (error != CL_SUCCESS) { |
| | | throw("Error setting kernel arguments!\n"); |
| | | throw string("Error setting kernel arguments!\n"); |
| | | } |
| | | //执行内核 |
| | | size_t globalWorkSize[1] = { resultSize }; |
| | |
| | | error = clEnqueueNDRangeKernel(queue, kernel, work_dim, NULL, globalWorkSize, |
| | | localWorkSize, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw("Error queuing kernel for execution!\n"); |
| | | throw string("Error queuing kernel for execution!\n"); |
| | | } |
| | | |
| | | //读取执行结果 |
| | | error = clEnqueueReadBuffer(queue, memObject4, CL_TRUE, 0, resultSize * sizeof(unsigned char), |
| | | result, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw("Error reading result buffer!\n"); |
| | | throw string("Error reading result buffer!\n"); |
| | | } |
| | | /* |
| | | printf("结果1:\n"); |
| | |
| | | |
| | | kernel = clCreateKernel(program, "recognition_numbers_2", &error); |
| | | if (kernel == NULL) { |
| | | throw("Couldn't create kernel!\n"); |
| | | throw string("Couldn't create kernel!\n"); |
| | | } |
| | | |
| | | cl_mem memObject21 = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(unsigned char) * resultSize, result, &error); |
| | | if (error < 0) { |
| | | throw("Creat memObject1 failed!\n"); |
| | | throw string("Creat memObject1 failed!\n"); |
| | | } |
| | | |
| | | cl_mem memObject22 = clCreateBuffer(context, CL_MEM_WRITE_ONLY, |
| | |
| | | error |= clSetKernelArg(kernel, 1, sizeof(cl_mem), &memObject22); |
| | | |
| | | if (error != CL_SUCCESS) { |
| | | throw("Error setting kernel arguments!\n"); |
| | | throw string("Error setting kernel arguments!\n"); |
| | | } |
| | | size_t globalWorkSize2[1] = { resultSize2 }; |
| | | error = clEnqueueNDRangeKernel(queue, kernel, work_dim, NULL, globalWorkSize2, |
| | | localWorkSize, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw("Error queuing kernel for execution!\n"); |
| | | throw string("Error queuing kernel for execution!\n"); |
| | | } |
| | | |
| | | //读取执行结果 |
| | | error = clEnqueueReadBuffer(queue, memObject22, CL_TRUE, 0, resultSize2 * sizeof(unsigned char), |
| | | result2, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw("Error reading result buffer!\n"); |
| | | throw string("Error reading result buffer!\n"); |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | kernel = clCreateKernel(program, "split_plate_num", &error); |
| | | if (kernel == NULL) { |
| | | throw("Couldn't create kernel!\n"); |
| | | throw string("Couldn't create kernel!\n"); |
| | | } |
| | | |
| | | int inputSize = (img.cols * img.rows); |
| | |
| | | |
| | | cl_mem memObject1 = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(unsigned char) * inputSize, img.data, &error); |
| | | if (error < 0) { |
| | | throw("Creat memObject1 failed!\n"); |
| | | throw string("Creat memObject1 failed!\n"); |
| | | } |
| | | |
| | | cl_mem memObject2 = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, |
| | | sizeof(int) * pos.length * 4, pos.data, &error); |
| | | if (error < 0) { |
| | | throw("Creat memObject2 failed!\n"); |
| | | throw string("Creat memObject2 failed!\n"); |
| | | } |
| | | |
| | | cl_mem memObject3 = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, |
| | | sizeof(unsigned char) * num_width * num_height, zero, &error); |
| | | if (error < 0) { |
| | | throw("Creat memObject3 failed!\n"); |
| | | throw string("Creat memObject3 failed!\n"); |
| | | } |
| | | |
| | | cl_mem memObject4 = clCreateBuffer(context, CL_MEM_WRITE_ONLY, |
| | | sizeof(unsigned char) * resultSize, NULL, &error); |
| | | if (error < 0) { |
| | | throw("Creat memObject4 failed!\n"); |
| | | throw string("Creat memObject4 failed!\n"); |
| | | } |
| | | |
| | | |
| | |
| | | cl_mem memObject5 = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, |
| | | sizeof(unsigned char) * types.length, types.data, &error); |
| | | if (error < 0) { |
| | | throw("Creat memObject5 failed!\n"); |
| | | throw string("Creat memObject5 failed!\n"); |
| | | } |
| | | |
| | | //设置内核参数 |
| | |
| | | error |= clSetKernelArg(kernel, 8, sizeof(int), &length_per_num); |
| | | error |= clSetKernelArg(kernel, 9, sizeof(cl_mem), &memObject4); |
| | | if (error != CL_SUCCESS) { |
| | | throw("Error setting kernel arguments!\n"); |
| | | throw string("Error setting kernel arguments!\n"); |
| | | } |
| | | //执行内核 |
| | | size_t globalWorkSize[1] = { pos.length }; |
| | |
| | | error = clEnqueueNDRangeKernel(queue, kernel, work_dim, NULL, globalWorkSize, |
| | | localWorkSize, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw("Error queuing kernel for execution!\n"); |
| | | throw string("Error queuing kernel for execution!\n"); |
| | | } |
| | | |
| | | //读取执行结果 |
| | | error = clEnqueueReadBuffer(queue, memObject4, CL_TRUE, 0, resultSize * sizeof(unsigned char), |
| | | result.data, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw("Error reading result buffer!\n"); |
| | | throw string("Error reading result buffer!\n"); |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | kernel = clCreateKernel(program, "split_l2_num_new", &error); |
| | | if (kernel == NULL) { |
| | | throw("Couldn't create kernel!\n"); |
| | | throw string("Couldn't create kernel!\n"); |
| | | } |
| | | |
| | | int inputSize = (img.cols * img.rows); |
| | |
| | | |
| | | cl_mem memObject1 = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(unsigned char) * inputSize, img.data, &error); |
| | | if (error < 0) { |
| | | throw("Creat memObject1 failed!\n"); |
| | | throw string("Creat memObject1 failed!\n"); |
| | | } |
| | | |
| | | cl_mem memObject2 = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, |
| | | sizeof(int) * pos.length * 4, pos.data, &error); |
| | | if (error < 0) { |
| | | throw("Creat memObject2 failed!\n"); |
| | | throw string("Creat memObject2 failed!\n"); |
| | | } |
| | | |
| | | cl_mem memObject3 = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, |
| | | sizeof(unsigned char) * num_width * num_height, zero, &error); |
| | | if (error < 0) { |
| | | throw("Creat memObject3 failed!\n"); |
| | | throw string("Creat memObject3 failed!\n"); |
| | | } |
| | | |
| | | cl_mem memObject4 = clCreateBuffer(context, CL_MEM_WRITE_ONLY, |
| | | sizeof(unsigned char) * resultSize, NULL, &error); |
| | | if (error < 0) { |
| | | throw("Creat memObject4 failed!\n"); |
| | | throw string("Creat memObject4 failed!\n"); |
| | | } |
| | | |
| | | |
| | |
| | | cl_mem memObject5 = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, |
| | | sizeof(unsigned char) * types.length, types.data, &error); |
| | | if (error < 0) { |
| | | throw("Creat memObject5 failed!\n"); |
| | | throw string("Creat memObject5 failed!\n"); |
| | | } |
| | | |
| | | //设置内核参数 |
| | |
| | | error |= clSetKernelArg(kernel, 8, sizeof(int), &length_per_num); |
| | | error |= clSetKernelArg(kernel, 9, sizeof(cl_mem), &memObject4); |
| | | if (error != CL_SUCCESS) { |
| | | throw("Error setting kernel arguments!\n"); |
| | | throw string("Error setting kernel arguments!\n"); |
| | | } |
| | | //执行内核 |
| | | size_t globalWorkSize[1] = { pos.length }; |
| | |
| | | error = clEnqueueNDRangeKernel(queue, kernel, work_dim, NULL, globalWorkSize, |
| | | localWorkSize, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw("Error queuing kernel for execution!\n"); |
| | | throw string("Error queuing kernel for execution!\n"); |
| | | } |
| | | |
| | | //读取执行结果 |
| | | error = clEnqueueReadBuffer(queue, memObject4, CL_TRUE, 0, resultSize * sizeof(unsigned char), |
| | | result.data, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw("Error reading result buffer!\n"); |
| | | throw string("Error reading result buffer!\n"); |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | kernel = clCreateKernel(program, "split_plate_num", &error); |
| | | if (kernel == NULL) { |
| | | throw("Couldn't create kernel!\n"); |
| | | throw string("Couldn't create kernel!\n"); |
| | | } |
| | | |
| | | int inputSize = (img_width * img_height); |
| | |
| | | |
| | | cl_mem memObject1 = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(unsigned char) * inputSize, img, &error); |
| | | if (error < 0) { |
| | | throw("Creat memObject1 failed!\n"); |
| | | throw string("Creat memObject1 failed!\n"); |
| | | } |
| | | |
| | | cl_mem memObject2 = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, |
| | | sizeof(int) * pos_count * 4, pos, &error); |
| | | if (error < 0) { |
| | | throw("Creat memObject2 failed!\n"); |
| | | throw string("Creat memObject2 failed!\n"); |
| | | } |
| | | |
| | | cl_mem memObject3 = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, |
| | | sizeof(unsigned char) * num_width * num_height, zero, &error); |
| | | if (error < 0) { |
| | | throw("Creat memObject3 failed!\n"); |
| | | throw string("Creat memObject3 failed!\n"); |
| | | } |
| | | |
| | | cl_mem memObject4 = clCreateBuffer(context, CL_MEM_WRITE_ONLY, |
| | | sizeof(unsigned char) * resultSize, NULL, &error); |
| | | if (error < 0) { |
| | | throw("Creat memObject4 failed!\n"); |
| | | throw string("Creat memObject4 failed!\n"); |
| | | } |
| | | |
| | | |
| | |
| | | cl_mem memObject5 = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, |
| | | sizeof(unsigned char) * 4, types, &error); |
| | | if (error < 0) { |
| | | throw("Creat memObject5 failed!\n"); |
| | | throw string("Creat memObject5 failed!\n"); |
| | | } |
| | | |
| | | int ele_count_line = 4; |
| | |
| | | error |= clSetKernelArg(kernel, 8, sizeof(int), &length_per_num); |
| | | error |= clSetKernelArg(kernel, 9, sizeof(cl_mem), &memObject4); |
| | | if (error != CL_SUCCESS) { |
| | | throw("Error setting kernel arguments!\n"); |
| | | throw string("Error setting kernel arguments!\n"); |
| | | } |
| | | //执行内核 |
| | | size_t globalWorkSize[1] = { pos_count }; |
| | |
| | | error = clEnqueueNDRangeKernel(queue, kernel, work_dim, NULL, globalWorkSize, |
| | | localWorkSize, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw("Error queuing kernel for execution!\n"); |
| | | throw string("Error queuing kernel for execution!\n"); |
| | | } |
| | | |
| | | //读取执行结果 |
| | | error = clEnqueueReadBuffer(queue, memObject4, CL_TRUE, 0, resultSize * sizeof(unsigned char), |
| | | result, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw("Error reading result buffer!\n"); |
| | | throw string("Error reading result buffer!\n"); |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | kernel = clCreateKernel(program, "split_l2_num", &error); |
| | | if (kernel == NULL) { |
| | | throw("Couldn't create kernel!\n"); |
| | | throw string("Couldn't create kernel!\n"); |
| | | } |
| | | |
| | | int inputSize = (img_width * img_height); |
| | |
| | | |
| | | cl_mem memObject1 = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(unsigned char) * inputSize, img, &error); |
| | | if (error < 0) { |
| | | throw("Creat memObject1 failed!\n"); |
| | | throw string("Creat memObject1 failed!\n"); |
| | | } |
| | | |
| | | cl_mem memObject2 = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, |
| | | sizeof(int) * pos_count * 4, pos, &error); |
| | | if (error < 0) { |
| | | throw("Creat memObject2 failed!\n"); |
| | | throw string("Creat memObject2 failed!\n"); |
| | | } |
| | | |
| | | cl_mem memObject3 = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, |
| | | sizeof(unsigned char) * num_width * num_height, zero, &error); |
| | | if (error < 0) { |
| | | throw("Creat memObject3 failed!\n"); |
| | | throw string("Creat memObject3 failed!\n"); |
| | | } |
| | | |
| | | cl_mem memObject4 = clCreateBuffer(context, CL_MEM_WRITE_ONLY, |
| | | sizeof(unsigned char) * resultSize, NULL, &error); |
| | | if (error < 0) { |
| | | throw("Creat memObject4 failed!\n"); |
| | | throw string("Creat memObject4 failed!\n"); |
| | | } |
| | | |
| | | //设置内核参数 |
| | |
| | | error |= clSetKernelArg(kernel, 6, sizeof(int), &num_count); |
| | | error |= clSetKernelArg(kernel, 7, sizeof(cl_mem), &memObject4); |
| | | if (error != CL_SUCCESS) { |
| | | throw("Error setting kernel arguments!\n"); |
| | | throw string("Error setting kernel arguments!\n"); |
| | | } |
| | | //执行内核 |
| | | size_t globalWorkSize[1] = { pos_count }; |
| | |
| | | error = clEnqueueNDRangeKernel(queue, kernel, work_dim, NULL, globalWorkSize, |
| | | localWorkSize, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw("Error queuing kernel for execution!\n"); |
| | | throw string("Error queuing kernel for execution!\n"); |
| | | } |
| | | |
| | | //读取执行结果 |
| | | error = clEnqueueReadBuffer(queue, memObject4, CL_TRUE, 0, resultSize * sizeof(unsigned char), |
| | | result, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw("Error reading result buffer!\n"); |
| | | throw string("Error reading result buffer!\n"); |
| | | } |
| | | |
| | | |
| | |
| | | void OpenCLExcuter::createNumberTemplates(int lines, int num_width, int num_height, int num_count, uchar* numsOneLevelData, unsigned char* result) { |
| | | kernel = clCreateKernel(program, "createTemplateNumbers", &error); |
| | | if (kernel == NULL) { |
| | | throw("Couldn't create kernel!\n"); |
| | | throw string("Couldn't create kernel!\n"); |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | cl_mem memObject1 = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(uchar) * inputSize, numsOneLevelData, &error); |
| | | if (error < 0) { |
| | | throw("Creat memObject1 failed!\n"); |
| | | throw string("Creat memObject1 failed!\n"); |
| | | } |
| | | |
| | | |
| | | cl_mem memObject2 = clCreateBuffer(context, CL_MEM_WRITE_ONLY, |
| | | sizeof(unsigned char) * resultSize, NULL, &error); |
| | | if (error < 0) { |
| | | throw("Creat memObject2 failed!\n"); |
| | | throw string("Creat memObject2 failed!\n"); |
| | | } |
| | | |
| | | |
| | |
| | | error |= clSetKernelArg(kernel, 4, sizeof(cl_mem), &memObject2); |
| | | |
| | | if (error != CL_SUCCESS) { |
| | | throw("Error setting kernel arguments!\n"); |
| | | throw string("Error setting kernel arguments!\n"); |
| | | } |
| | | //执行内核 |
| | | size_t globalWorkSize[1] = { lines }; |
| | |
| | | error = clEnqueueNDRangeKernel(queue, kernel, work_dim, NULL, globalWorkSize, |
| | | localWorkSize, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw("Error queuing kernel for execution!\n"); |
| | | throw string("Error queuing kernel for execution!\n"); |
| | | } |
| | | |
| | | //读取执行结果 |
| | | error = clEnqueueReadBuffer(queue, memObject2, CL_TRUE, 0, resultSize * sizeof(unsigned char), |
| | | result, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw("Error reading result buffer!\n"); |
| | | throw string("Error reading result buffer!\n"); |
| | | } |
| | | |
| | | clReleaseKernel(kernel); |
| | |
| | | |
| | | kernel = clCreateKernel(program, "splitL2RowData", &error); |
| | | if (kernel == NULL) { |
| | | throw("Couldn't create kernel!\n"); |
| | | throw string("Couldn't create kernel!\n"); |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | cl_mem memObject1 = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(uchar) * inputSize, imgs, &error); |
| | | if (error < 0) { |
| | | throw("Creat memObject1 failed!\n"); |
| | | throw string("Creat memObject1 failed!\n"); |
| | | } |
| | | |
| | | cl_mem memObject2 = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(int) * lines * 4, rowIndexs, &error); |
| | | if (error < 0) { |
| | | throw("Creat memObject2 failed!\n"); |
| | | throw string("Creat memObject2 failed!\n"); |
| | | } |
| | | |
| | | |
| | | cl_mem memObject3 = clCreateBuffer(context, CL_MEM_WRITE_ONLY, |
| | | sizeof(int) * resultSize, NULL, &error); |
| | | if (error < 0) { |
| | | throw("Creat memObject3 failed!\n"); |
| | | throw string("Creat memObject3 failed!\n"); |
| | | } |
| | | |
| | | |
| | |
| | | error |= clSetKernelArg(kernel, 3, sizeof(cl_mem), &memObject3); |
| | | |
| | | if (error != CL_SUCCESS) { |
| | | throw("Error setting kernel arguments!\n"); |
| | | throw string("Error setting kernel arguments!\n"); |
| | | } |
| | | //执行内核 |
| | | size_t globalWorkSize[1] = { lines }; |
| | |
| | | error = clEnqueueNDRangeKernel(queue, kernel, work_dim, NULL, globalWorkSize, |
| | | localWorkSize, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw("Error queuing kernel for execution!\n"); |
| | | throw string("Error queuing kernel for execution!\n"); |
| | | } |
| | | |
| | | //读取执行结果 |
| | | error = clEnqueueReadBuffer(queue, memObject3, CL_TRUE, 0, resultSize * sizeof(int), |
| | | result, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw("Error reading result buffer!\n"); |
| | | throw string("Error reading result buffer!\n"); |
| | | } |
| | | |
| | | //printf("%d %d %d %d \n", result[0], result[1], result[2], result[3]); |
| | |
| | | |
| | | kernel = clCreateKernel(program, "splitCommonRowData", &error); |
| | | if (kernel == NULL) { |
| | | throw("Couldn't create kernel!\n"); |
| | | throw string("Couldn't create kernel!\n"); |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | cl_mem memObject1 = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(uchar) * inputSize, imgs, &error); |
| | | if (error < 0) { |
| | | throw("Creat memObject1 failed!\n"); |
| | | throw string("Creat memObject1 failed!\n"); |
| | | } |
| | | |
| | | cl_mem memObject2 = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(int) * lines * 4, rowIndexs, &error); |
| | | if (error < 0) { |
| | | throw("Creat memObject2 failed!\n"); |
| | | throw string("Creat memObject2 failed!\n"); |
| | | } |
| | | |
| | | |
| | | cl_mem memObject3 = clCreateBuffer(context, CL_MEM_WRITE_ONLY, |
| | | sizeof(int) * resultSize, NULL, &error); |
| | | if (error < 0) { |
| | | throw("Creat memObject3 failed!\n"); |
| | | throw string("Creat memObject3 failed!\n"); |
| | | } |
| | | |
| | | |
| | |
| | | error |= clSetKernelArg(kernel, 5, sizeof(cl_mem), &memObject3); |
| | | |
| | | if (error != CL_SUCCESS) { |
| | | throw("Error setting kernel arguments!\n"); |
| | | throw string("Error setting kernel arguments!\n"); |
| | | } |
| | | //执行内核 |
| | | size_t globalWorkSize[1] = { lines }; |
| | |
| | | error = clEnqueueNDRangeKernel(queue, kernel, work_dim, NULL, globalWorkSize, |
| | | localWorkSize, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw("Error queuing kernel for execution!\n"); |
| | | throw string("Error queuing kernel for execution!\n"); |
| | | } |
| | | |
| | | //读取执行结果 |
| | | error = clEnqueueReadBuffer(queue, memObject3, CL_TRUE, 0, resultSize * sizeof(int), |
| | | result, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw("Error reading result buffer!\n"); |
| | | throw string("Error reading result buffer!\n"); |
| | | } |
| | | |
| | | //printf("%d %d %d %d \n", result[0], result[1], result[2], result[3]); |
| | |
| | | |
| | | kernel = clCreateKernel(program, "recognition_not_num", &error); |
| | | if (kernel == NULL) { |
| | | throw("Couldn't create kernel!\n"); |
| | | throw string("Couldn't create kernel!\n"); |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | cl_mem memObject1 = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(uchar) * inputSize, imgs, &error); |
| | | if (error < 0) { |
| | | throw("Creat memObject1 failed!\n"); |
| | | throw string("Creat memObject1 failed!\n"); |
| | | } |
| | | |
| | | cl_mem memObject2 = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(int) * lines * 4 * colCount, rowIndexs, &error); |
| | | if (error < 0) { |
| | | throw("Creat memObject2 failed!\n"); |
| | | throw string("Creat memObject2 failed!\n"); |
| | | } |
| | | |
| | | |
| | | cl_mem memObject3 = clCreateBuffer(context, CL_MEM_WRITE_ONLY, |
| | | sizeof(int) * resultSize, NULL, &error); |
| | | if (error < 0) { |
| | | throw("Creat memObject3 failed!\n"); |
| | | throw string("Creat memObject3 failed!\n"); |
| | | } |
| | | |
| | | |
| | |
| | | error |= clSetKernelArg(kernel, 3, sizeof(cl_mem), &memObject3); |
| | | |
| | | if (error != CL_SUCCESS) { |
| | | throw("Error setting kernel arguments!\n"); |
| | | throw string("Error setting kernel arguments!\n"); |
| | | } |
| | | //执行内核 |
| | | size_t globalWorkSize[1] = { resultSize }; |
| | |
| | | error = clEnqueueNDRangeKernel(queue, kernel, work_dim, NULL, globalWorkSize, |
| | | localWorkSize, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw("Error queuing kernel for execution!\n"); |
| | | throw string("Error queuing kernel for execution!\n"); |
| | | } |
| | | |
| | | //读取执行结果 |
| | | error = clEnqueueReadBuffer(queue, memObject3, CL_TRUE, 0, resultSize * sizeof(int), |
| | | result, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw("Error reading result buffer!\n"); |
| | | throw string("Error reading result buffer!\n"); |
| | | } |
| | | |
| | | //printf("%d %d %d %d \n", result[0], result[1], result[2], result[3]); |
| | |
| | | |
| | | kernel = clCreateKernel(program, "recognition_plate_money_unit", &error); |
| | | if (kernel == NULL) { |
| | | throw("Couldn't create kernel!\n"); |
| | | throw string("Couldn't create kernel!\n"); |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | cl_mem memObject1 = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(uchar) * inputSize, imgs, &error); |
| | | if (error < 0) { |
| | | throw("Creat memObject1 failed!\n"); |
| | | throw string("Creat memObject1 failed!\n"); |
| | | } |
| | | |
| | | cl_mem memObject2 = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(int) * lines * 4 * colEleCount, rowIndexs, &error); |
| | | if (error < 0) { |
| | | throw("Creat memObject2 failed!\n"); |
| | | throw string("Creat memObject2 failed!\n"); |
| | | } |
| | | |
| | | |
| | | cl_mem memObject3 = clCreateBuffer(context, CL_MEM_WRITE_ONLY, |
| | | sizeof(int) * resultSize, NULL, &error); |
| | | if (error < 0) { |
| | | throw("Creat memObject3 failed!\n"); |
| | | throw string("Creat memObject3 failed!\n"); |
| | | } |
| | | |
| | | |
| | |
| | | error |= clSetKernelArg(kernel, 3, sizeof(cl_mem), &memObject3); |
| | | |
| | | if (error != CL_SUCCESS) { |
| | | throw("Error setting kernel arguments!\n"); |
| | | throw string("Error setting kernel arguments!\n"); |
| | | } |
| | | //执行内核 |
| | | size_t globalWorkSize[1] = { resultSize }; |
| | |
| | | error = clEnqueueNDRangeKernel(queue, kernel, work_dim, NULL, globalWorkSize, |
| | | localWorkSize, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw("Error queuing kernel for execution!\n"); |
| | | throw string("Error queuing kernel for execution!\n"); |
| | | } |
| | | |
| | | //读取执行结果 |
| | | error = clEnqueueReadBuffer(queue, memObject3, CL_TRUE, 0, resultSize * sizeof(int), |
| | | result, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw("Error reading result buffer!\n"); |
| | | throw string("Error reading result buffer!\n"); |
| | | } |
| | | |
| | | //printf("%d %d %d %d \n", result[0], result[1], result[2], result[3]); |
| | |
| | | |
| | | kernel = clCreateKernel(program, "rgb2GrayImg", &error); |
| | | if (kernel == NULL) { |
| | | throw("Couldn't create kernel!\n"); |
| | | throw string("Couldn't create kernel!\n"); |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | cl_mem memObject1 = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(uchar) * inputSize, imgs, &error); |
| | | if (error < 0) { |
| | | throw("Creat memObject1 failed!\n"); |
| | | throw string("Creat memObject1 failed!\n"); |
| | | } |
| | | |
| | | cl_mem memObject2 = clCreateBuffer(context, CL_MEM_WRITE_ONLY, |
| | | sizeof(uchar) * resultSize, NULL, &error); |
| | | if (error < 0) { |
| | | throw("Creat memObject2 failed!\n"); |
| | | throw string("Creat memObject2 failed!\n"); |
| | | } |
| | | |
| | | |
| | |
| | | error = clSetKernelArg(kernel, 2, sizeof(cl_mem), &memObject2); |
| | | |
| | | if (error != CL_SUCCESS) { |
| | | throw("Error setting kernel arguments!\n"); |
| | | throw string("Error setting kernel arguments!\n"); |
| | | } |
| | | //执行内核 |
| | | size_t globalWorkSize[1] = { imgHeight }; |
| | |
| | | error = clEnqueueNDRangeKernel(queue, kernel, work_dim, NULL, globalWorkSize, |
| | | localWorkSize, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw("Error queuing kernel for execution!\n"); |
| | | throw string("Error queuing kernel for execution!\n"); |
| | | } |
| | | |
| | | //读取执行结果 |
| | | error = clEnqueueReadBuffer(queue, memObject2, CL_TRUE, 0, resultSize * sizeof(uchar), |
| | | result, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw("Error reading result buffer!\n"); |
| | | throw string("Error reading result buffer!\n"); |
| | | } |
| | | |
| | | clReleaseKernel(kernel); |
| | |
| | | |
| | | kernel = clCreateKernel(program, "rgba2GrayImg", &error); |
| | | if (kernel == NULL) { |
| | | throw("Couldn't create kernel!\n"); |
| | | throw string("Couldn't create kernel!\n"); |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | cl_mem memObject1 = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(uchar) * inputSize, imgs, &error); |
| | | if (error < 0) { |
| | | throw("Creat memObject1 failed!\n"); |
| | | throw string("Creat memObject1 failed!\n"); |
| | | } |
| | | |
| | | cl_mem memObject2 = clCreateBuffer(context, CL_MEM_WRITE_ONLY, |
| | | sizeof(uchar) * resultSize, NULL, &error); |
| | | if (error < 0) { |
| | | throw("Creat memObject2 failed!\n"); |
| | | throw string("Creat memObject2 failed!\n"); |
| | | } |
| | | |
| | | |
| | |
| | | error = clSetKernelArg(kernel, 2, sizeof(cl_mem), &memObject2); |
| | | |
| | | if (error != CL_SUCCESS) { |
| | | throw("Error setting kernel arguments!\n"); |
| | | throw string("Error setting kernel arguments!\n"); |
| | | } |
| | | //执行内核 |
| | | size_t globalWorkSize[1] = { imgHeight }; |
| | |
| | | error = clEnqueueNDRangeKernel(queue, kernel, work_dim, NULL, globalWorkSize, |
| | | localWorkSize, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw("Error queuing kernel for execution!\n"); |
| | | throw string("Error queuing kernel for execution!\n"); |
| | | } |
| | | |
| | | //读取执行结果 |
| | | error = clEnqueueReadBuffer(queue, memObject2, CL_TRUE, 0, resultSize * sizeof(uchar), |
| | | result, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw("Error reading result buffer!\n"); |
| | | throw string("Error reading result buffer!\n"); |
| | | } |
| | | |
| | | clReleaseKernel(kernel); |
| | |
| | | |
| | | kernel = clCreateKernel(program, "rgb2ThresholdInvert", &error); |
| | | if (kernel == NULL) { |
| | | throw("Couldn't create kernel!\n"); |
| | | throw string("Couldn't create kernel!\n"); |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | cl_mem memObject1 = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(uchar) * inputSize, imgs, &error); |
| | | if (error < 0) { |
| | | throw("Creat memObject1 failed!\n"); |
| | | throw string("Creat memObject1 failed!\n"); |
| | | } |
| | | |
| | | cl_mem memObject2 = clCreateBuffer(context, CL_MEM_WRITE_ONLY, |
| | | sizeof(uchar) * resultSize, NULL, &error); |
| | | if (error < 0) { |
| | | throw("Creat memObject2 failed!\n"); |
| | | throw string("Creat memObject2 failed!\n"); |
| | | } |
| | | |
| | | |
| | |
| | | error = clSetKernelArg(kernel, 2, sizeof(cl_mem), &memObject2); |
| | | |
| | | if (error != CL_SUCCESS) { |
| | | throw("Error setting kernel arguments!\n"); |
| | | throw string("Error setting kernel arguments!\n"); |
| | | } |
| | | //执行内核 |
| | | size_t globalWorkSize[1] = { imgHeight }; |
| | |
| | | error = clEnqueueNDRangeKernel(queue, kernel, work_dim, NULL, globalWorkSize, |
| | | localWorkSize, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw("Error queuing kernel for execution!\n"); |
| | | throw string("Error queuing kernel for execution!\n"); |
| | | } |
| | | |
| | | //读取执行结果 |
| | | error = clEnqueueReadBuffer(queue, memObject2, CL_TRUE, 0, resultSize * sizeof(uchar), |
| | | result, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw("Error reading result buffer!\n"); |
| | | throw string("Error reading result buffer!\n"); |
| | | } |
| | | |
| | | clReleaseKernel(kernel); |
| | |
| | | |
| | | kernel = clCreateKernel(program, "rgba2ThresholdInvert", &error); |
| | | if (kernel == NULL) { |
| | | throw("Couldn't create kernel!\n"); |
| | | throw string("Couldn't create kernel!\n"); |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | cl_mem memObject1 = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(uchar) * inputSize, imgs, &error); |
| | | if (error < 0) { |
| | | throw("Creat memObject1 failed!\n"); |
| | | throw string("Creat memObject1 failed!\n"); |
| | | } |
| | | |
| | | cl_mem memObject2 = clCreateBuffer(context, CL_MEM_WRITE_ONLY, |
| | | sizeof(uchar) * resultSize, NULL, &error); |
| | | if (error < 0) { |
| | | throw("Creat memObject2 failed!\n"); |
| | | throw string("Creat memObject2 failed!\n"); |
| | | } |
| | | |
| | | |
| | |
| | | error = clSetKernelArg(kernel, 2, sizeof(cl_mem), &memObject2); |
| | | |
| | | if (error != CL_SUCCESS) { |
| | | throw("Error setting kernel arguments!\n"); |
| | | throw string("Error setting kernel arguments!\n"); |
| | | } |
| | | //执行内核 |
| | | size_t globalWorkSize[1] = { imgHeight }; |
| | |
| | | error = clEnqueueNDRangeKernel(queue, kernel, work_dim, NULL, globalWorkSize, |
| | | localWorkSize, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw("Error queuing kernel for execution!\n"); |
| | | throw string("Error queuing kernel for execution!\n"); |
| | | } |
| | | |
| | | //读取执行结果 |
| | | error = clEnqueueReadBuffer(queue, memObject2, CL_TRUE, 0, resultSize * sizeof(uchar), |
| | | result, 0, NULL, NULL); |
| | | if (error != CL_SUCCESS) { |
| | | throw("Error reading result buffer!\n"); |
| | | throw string("Error reading result buffer!\n"); |
| | | } |
| | | |
| | | clReleaseKernel(kernel); |