Академический Документы
Профессиональный Документы
Культура Документы
____________________________________________________________________________________
LAB 22
Part List:
Nvidia Jetson TX2 Board
Power adapter
Hard Disk with Ubuntu 16.04
Ethernet connection
Nsight Eclipse Edition
OpenCV 3.4.0
PC
Jetpack
Cuda Toolkit 9.0
SSD card
Hardware Connection:
Connect the Jetson board to the monitor with an HDMI cable.
Connect the adapter to power ON the board.
Connect ethernet to the host PC and the Jetson Board.
Included Files:
Header Files
iostream
cstdio
opencv2/opencv.hpp
opencv2/cudalegacy.hpp
opencv2/core.hpp
opencv2/core/utility.hpp
vector
fstream
Library Files:
opencv_calib3d
opencv_core
opencv_features2d
opencv_flann
opencv_highgui
opencv_imgcodecs
opencv_imgproc
____________________________________________________________________________________
Edutech Learning Solutions Pvt. Ltd. info@edutechlearning.com
Laboratory workbook for Image Processing using GPU
____________________________________________________________________________________
opencv_ml
opencv_objdetect
opencv_photo
opencv_shape
opencv_stitching
opencv_superres
opencv_video
opencv_videoio
opencv_videostab
opencv_cudalegacy
opencv_cudabgsegm
opencv_cudaimgproc
opencv_cudawarping
opencv_cudafilters
opencv_cudaarithm
____________________________________________________________________________________
Edutech Learning Solutions Pvt. Ltd. info@edutechlearning.com
Laboratory workbook for Image Processing using GPU
____________________________________________________________________________________
Program Listing:
if (scale != 1)
{
cv::resize(gray, resized, sz);
}
else
{
resized = gray;
}
}
if (scale != 1)
{
cv::cuda::resize(gray, resized, sz);
____________________________________________________________________________________
Edutech Learning Solutions Pvt. Ltd. info@edutechlearning.com
Laboratory workbook for Image Processing using GPU
____________________________________________________________________________________
}
else
{
resized = gray;
}
}
Point org;
org.x = 1;
org.y = 3 * fontSize.height * (lineOffsY + 1) / 2;
putText(img, ss, org, fontFace, fontScale, Scalar(0,0,0),
5*fontThickness/2, 16);
putText(img, ss, org, fontFace, fontScale, fontColor,
fontThickness, 16);
}
ostringstream ss;
ss << "FPS = " << setprecision(1) << fixed << fps;
matPrint(canvas, 0, fontColorRed, ss.str());
ss.str("");
ss << "[" << canvas.cols << "x" << canvas.rows << "], " <<
(bGpu ? "GPU, " : "CPU, ") <<
(bLargestFace ? "OneFace, " : "MultiFace, ") <<
(bFilter ? "Filter:ON" : "Filter:OFF");
matPrint(canvas, 1, fontColorRed, ss.str());
____________________________________________________________________________________
Edutech Learning Solutions Pvt. Ltd. info@edutechlearning.com
Laboratory workbook for Image Processing using GPU
____________________________________________________________________________________
else
{
matPrint(canvas, 2, fontColorNV, "H - toggle hotkeys help");
}
}
if (getCudaEnabledDeviceCount() == 0)
{
return cerr << "No GPU found or the library is compiled
without CUDA support" << endl, -1;
}
cv::cuda::printShortCudaDeviceInfo(cv::cuda::getDevice());
string inputName;
string cascadeName;
bool isInputImage = false;
bool isInputVideo = false;
bool isInputCamera = false;
Ptr<cuda::CascadeClassifier> cascade_gpu =
cuda::CascadeClassifier::create("/home/nvidia/opencv-
3.4.0/data/haarcascades_cuda/haarcascade_fullbody.xml");
cv::CascadeClassifier cascade_cpu;
____________________________________________________________________________________
Edutech Learning Solutions Pvt. Ltd. info@edutechlearning.com
Laboratory workbook for Image Processing using GPU
____________________________________________________________________________________
if (!cascade_cpu.load("/home/nvidia/opencv-
3.4.0/data/haarcascades_cuda/haarcascade_fullbody.xml"))
{
return cerr << "ERROR: Could not load cascade classifier
\""<< "\"" << endl, help(), -1;
}
cv::VideoCapture capture;
cv::Mat image;
if (isInputImage)
{
image = imread(inputName);
CV_Assert(!image.empty());
}
else if (isInputVideo)
{
capture.open(inputName);
CV_Assert(capture.isOpened());
}
else
{
capture.open(atoi(inputName.c_str()));
CV_Assert(capture.isOpened());
}
namedWindow("result", 1);
/* parameters */
bool useGPU = true;
double scaleFactor = 1.0;
bool findLargestObject = false;
bool filterRects = true;
bool helpScreen = false;
for (;;)
{
if (isInputCamera || isInputVideo)
{
capture >> frame;
if (frame.empty())
{
break;
}
}
____________________________________________________________________________________
Edutech Learning Solutions Pvt. Ltd. info@edutechlearning.com
Laboratory workbook for Image Processing using GPU
____________________________________________________________________________________
TickMeter tm;
tm.start();
if (useGPU)
{
cascade_gpu->setFindLargestObject(findLargestObject);
cascade_gpu->setScaleFactor(1.2);
cascade_gpu->setMinNeighbors((filterRects ||
findLargestObject) ? 4 : 0);
cascade_gpu->detectMultiScale(resized_gpu,
facesBuf_gpu);
cascade_gpu->convert(facesBuf_gpu, faces);
}
else
{
Size minSize = cascade_gpu->getClassifierSize();
cascade_cpu.detectMultiScale(resized_cpu, faces, 1.2,
(filterRects ||
findLargestObject) ? 4 : 0,
(findLargestObject ?
CASCADE_FIND_BIGGEST_OBJECT : 0)
| CASCADE_SCALE_IMAGE,
minSize);
}
tm.stop();
double detectionTime = tm.getTimeMilli();
double fps = 1000 / detectionTime;
____________________________________________________________________________________
Edutech Learning Solutions Pvt. Ltd. info@edutechlearning.com
Laboratory workbook for Image Processing using GPU
____________________________________________________________________________________
break;
}
switch (key)
{
case ' ':
useGPU = !useGPU;
break;
case 'm':
case 'M':
findLargestObject = !findLargestObject;
break;
case 'f':
case 'F':
filterRects = !filterRects;
break;
case '1':
scaleFactor *= 1.05;
break;
case 'q':
case 'Q':
scaleFactor /= 1.05;
break;
case 'h':
case 'H':
helpScreen = !helpScreen;
break;
}
}
return 0;
}}
____________________________________________________________________________________
Edutech Learning Solutions Pvt. Ltd. info@edutechlearning.com
Laboratory workbook for Image Processing using GPU
____________________________________________________________________________________
____________________________________________________________________________________
Edutech Learning Solutions Pvt. Ltd. info@edutechlearning.com
Laboratory workbook for Image Processing using GPU
____________________________________________________________________________________
Result:
Above given code extracts the desired portion of the image.
Input: Output:
____________________________________________________________________________________
Edutech Learning Solutions Pvt. Ltd. info@edutechlearning.com
Laboratory workbook for Image Processing using GPU
____________________________________________________________________________________
____________________________________________________________________________________
Edutech Learning Solutions Pvt. Ltd. info@edutechlearning.com