Мне нужно выполнить обработку изображений на графическом процессоре для требования к классу. Выполняется ли этот код OpenCV на графическом процессоре или процессоре?Выполняется ли код OpenCV на графическом процессоре?
код
// The "Square Detector" program.
// It loads several images sequentially and tries to find squares in
// each image
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
#include <math.h>
#include <string.h>
using namespace cv;
using namespace std;
int thresh = 50, N = 11;
const char* wndname = "Square Detection Demo";
static void findSquares(const Mat& image, vector<vector<Point> >& squares)
{
squares.clear();
Mat pyr, timg, gray0(image.size(), CV_8U), gray;
pyrDown(image, pyr, Size(image.cols/2, image.rows/2));
pyrUp(pyr, timg, image.size());
vector<vector<Point> > contours;
// find squares in every color plane of the image
for(int c = 0; c < 3; c++)
{
int ch[] = {c, 0};
mixChannels(&timg, 1, &gray0, 1, ch, 1);
for(int l = 0; l < N; l++)
{
if(l == 0)
{
Canny(gray0, gray, 0, thresh, 5);
dilate(gray, gray, Mat(), Point(-1,-1));
}
else
{
gray = gray0 >= (l+1)*255/N;
}
findContours(gray, contours, RETR_LIST, CHAIN_APPROX_SIMPLE);
vector<Point> approx;
for(size_t i = 0; i < contours.size(); i++)
{
approxPolyDP(Mat(contours[i]), approx, arcLength(Mat(contours[i]), true)*0.02, true);
if(approx.size() == 4 &&
fabs(contourArea(Mat(approx))) > 1000 &&
isContourConvex(Mat(approx)))
{
double maxCosine = 0;
for(int j = 2; j < 5; j++)
{
// find the maximum cosine of the angle between joint edges
double cosine = fabs(angle(approx[j%4], approx[j-2], approx[j-1]));
maxCosine = MAX(maxCosine, cosine);
}
// if cosines of all angles are small
// (all angles are ~90 degree) then write quandrange
// vertices to resultant sequence
if(maxCosine < 0.3)
squares.push_back(approx);
}
}
}
}
}
только специальные функции выполняются на gpu (ocl :: cuda :: gpu: :) и некоторые/многие общие функции, если вы используете специальное оборудование или библиотеки (например, tegra, например, IPP) – Micka