|
| 1 | +#include <opencv2\highgui.hpp> |
| 2 | +#include <opencv2\core\ocl.hpp> |
| 3 | +#include <opencv2\videoio.hpp> |
| 4 | +#include <opencv2\imgproc.hpp> |
| 5 | +#include <opencv2\opencv.hpp> |
| 6 | +#include <iostream> |
| 7 | +#include <vector> |
| 8 | + |
| 9 | +using namespace cv; |
| 10 | +using namespace ocl; |
| 11 | +using namespace std; |
| 12 | + |
| 13 | +void printInfo() { |
| 14 | + vector<ocl::PlatformInfo> info; |
| 15 | + getPlatfomsInfo(info); |
| 16 | + |
| 17 | + PlatformInfo sdk = info.at(0); |
| 18 | + |
| 19 | + if (sdk.deviceNumber() < 1) return; |
| 20 | + |
| 21 | + cout << "******SDK*******" << endl; |
| 22 | + cout << "Name: " << sdk.name() << endl; |
| 23 | + cout << "Vendor: " << sdk.vendor() << endl; |
| 24 | + cout << "Version: " << sdk.version() << endl; |
| 25 | + cout << "Number of devices: " << sdk.deviceNumber() << endl; |
| 26 | + |
| 27 | + for (int i = 0; i < sdk.deviceNumber(); i++) { |
| 28 | + Device device; |
| 29 | + sdk.getDevice(device, i); |
| 30 | + |
| 31 | + cout << "\n*********************\nDevice " << i + 1 << endl; |
| 32 | + cout << "Vendor ID: " << device.vendorID() << endl; |
| 33 | + cout << "Vendor name: " << device.vendorName() << endl; |
| 34 | + cout << "Name: " << device.name() << endl; |
| 35 | + cout << "Driver version: " << device.driverVersion() << endl; |
| 36 | + |
| 37 | + if (device.isAMD()) cout << "<-- Is an AMD device -->" << endl; |
| 38 | + if (device.isIntel()) cout << "<-- Is a Intel device -->" << endl; |
| 39 | + if (device.isNVidia()) cout << "<-- Is a NVidia device -->" << endl; |
| 40 | + |
| 41 | + cout << "Global Memory size: " << device.globalMemSize() << endl; |
| 42 | + cout << "Memory cache size: " << device.globalMemCacheSize() << endl; |
| 43 | + cout << "Memory cache type: " << device.globalMemCacheType() << endl; |
| 44 | + cout << "Local Memory size: " << device.localMemSize() << endl; |
| 45 | + cout << "Local Memory type: " << device.localMemType() << endl; |
| 46 | + cout << "Max Clock frequency: " << device.maxClockFrequency() << endl; |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +int main() |
| 51 | +{ |
| 52 | + printInfo(); |
| 53 | + |
| 54 | + VideoCapture capture; |
| 55 | + |
| 56 | + if (!capture.open(0)) cout << "Error al abrir la camara." << endl; |
| 57 | + |
| 58 | + const String titleWindow = "%.2f FPS :: OpenCL %s :: [q] para %s"; |
| 59 | + const String nameWindow = "OpenCL & OpenCV (T-API)"; |
| 60 | + |
| 61 | + double elapsed_time = 0; |
| 62 | + double start_time = 0; |
| 63 | + double avgfps = 0; |
| 64 | + unsigned int nframes = 0; |
| 65 | + |
| 66 | + namedWindow(nameWindow); |
| 67 | + |
| 68 | + while (true) |
| 69 | + { |
| 70 | + double t = (double)getTickCount(); |
| 71 | + |
| 72 | + UMat uframe; |
| 73 | + capture >> uframe; |
| 74 | + |
| 75 | + if (uframe.empty()) continue; |
| 76 | + |
| 77 | + medianBlur(uframe, uframe, 3); |
| 78 | + blur(uframe, uframe, Size(11, 11)); |
| 79 | + |
| 80 | + char key = (char)waitKey(10); |
| 81 | + |
| 82 | + if (key == 27) break; |
| 83 | + if (key == 'q') ocl::setUseOpenCL(!ocl::useOpenCL()); |
| 84 | + |
| 85 | + t = (double)getTickCount() - t; |
| 86 | + double fps = getTickFrequency() / t; |
| 87 | + double alpha = ++nframes > 50 ? 0.01 : 1. / nframes; |
| 88 | + avgfps = avgfps * (1 - alpha) + fps * alpha; |
| 89 | + |
| 90 | + String message = format(titleWindow.c_str(), avgfps, |
| 91 | + ocl::useOpenCL() ? "ON" : "OFF", |
| 92 | + ocl::useOpenCL() ? "desactivar" : "activar"); |
| 93 | + |
| 94 | + Mat frm = uframe.getMat(ACCESS_RW); |
| 95 | + Mat rectangle_src(25, 412, CV_8UC3, Scalar(20, 20, 20)); |
| 96 | + Mat rectangle_dst = frm(Rect(5, 5, 412, 25)); |
| 97 | + |
| 98 | + addWeighted(rectangle_src, 0.5, rectangle_dst, 1.0 - 0.5, 0.0, rectangle_dst); |
| 99 | + |
| 100 | + putText(frm, message, Point(10, 20), FONT_HERSHEY_TRIPLEX, 0.5, Scalar(0, 255, 0), 1, LINE_AA); |
| 101 | + |
| 102 | + imshow(nameWindow, frm); |
| 103 | + } |
| 104 | + |
| 105 | + capture.release(); |
| 106 | + return 0; |
| 107 | +} |
| 108 | +// |
| 109 | +//int __main(int, char** argv) |
| 110 | +//{ |
| 111 | +// |
| 112 | +// //String dir = "C:/Developer/TEMP/opencv-master/samples/data/"; |
| 113 | +// |
| 114 | +// // Load and show images... |
| 115 | +// Mat source = imread("image.jpg", IMREAD_COLOR); |
| 116 | +// Mat destination = imread("destino2.jpg", IMREAD_COLOR); |
| 117 | +// Mat mask = imread("mask.jpg", IMREAD_COLOR); |
| 118 | +// |
| 119 | +// imshow("source", source); |
| 120 | +// imshow("mask", mask); |
| 121 | +// imshow("destination", destination); |
| 122 | +// |
| 123 | +// Mat result; |
| 124 | +// |
| 125 | +// Point p; // p will be near top right corner |
| 126 | +// p.x = (float)/*2 **/ destination.size().width / 3; |
| 127 | +// p.y = (float)destination.size().height / 3; |
| 128 | +// |
| 129 | +// seamlessClone(source, destination, mask, p, result, NORMAL_CLONE); |
| 130 | +// imshow("result", result); |
| 131 | +// |
| 132 | +// cout << "\nDone. Press any key to exit...\n"; |
| 133 | +// |
| 134 | +// waitKey(); // Wait for key press |
| 135 | +// |
| 136 | +// |
| 137 | +// //double t = (double)getTickCount(); |
| 138 | +// // ... |
| 139 | +// //t = (double)getTickCount() - t; |
| 140 | +// //double fps = getTickFrequency() / t; |
| 141 | +// //static double avgfps = 0; |
| 142 | +// //static int nframes = 0; |
| 143 | +// //nframes++; |
| 144 | +// //double alpha = nframes > 50 ? 0.01 : 1. / nframes; |
| 145 | +// //avgfps = avgfps*(1 - alpha) + fps*alpha; |
| 146 | +// |
| 147 | +// //putText(uframe, format("OpenCL: %s, fps: %.1f", ocl::useOpenCL() ? "ON" : "OFF", avgfps), |
| 148 | +// // Point(50, 30), FONT_HERSHEY_SIMPLEX, 0.8, Scalar(0, 255, 0), 2); |
| 149 | +// |
| 150 | +// |
| 151 | +// return 0; |
| 152 | +//} |
| 153 | +// |
0 commit comments