Difference between revisions of "CUVI by Example"
(24 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
==Motion Detection== | |||
<p>CUVI library comes with all the image processing essentials that can be used to build countless applications. For example the '''Computer Vision''' module of CUVI can be used for motion and intrusion detection in a live video stream and tracking an object of interest throughout series of cameras installed in a premises. The processing pipeline for motion detection goes as follows:</p> | <p>CUVI library comes with all the image processing essentials that can be used to build countless applications. For example the '''Computer Vision''' module of CUVI can be used for motion and intrusion detection in a live video stream and tracking an object of interest throughout series of cameras installed in a premises. The processing pipeline for motion detection goes as follows:</p> | ||
*Read a frame from the camera stream | *Read a frame from the camera stream | ||
Line 9: | Line 10: | ||
{| | {| | ||
|style="font-size:130%;"| | |style="font-size:130%;"| | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="cpp"> | ||
#include <cuvi.h> | #include <cuvi.h> | ||
Line 15: | Line 16: | ||
static const int width = 640; //Width of video frame | static const int width = 640; //Width of video frame | ||
static const int height = 480; //Height of video frame | static const int height = 480; //Height of video frame | ||
CuviFilter* f; // Declaring CUVI Filter | |||
//Parameters for feature selection | //Parameters for feature selection | ||
static const int requestedFeatures = 150; //Number of features to look for | static const int requestedFeatures = 150; //Number of features to look for | ||
static const float featureQuality = 0.006f; //Quality of a feature | static const float featureQuality = 0.006f; //Quality of a feature | ||
static const int featureMinDistance = | static const int featureMinDistance = 15; //Minimum distance between 2 features | ||
static const int blockSize = 3; //block size for computing Eigen Matrix | |||
static const float k = -2.0f; //k for Harris Corner detector | static const float k = -2.0f; //k for Harris Corner detector | ||
Line 43: | Line 46: | ||
} | } | ||
void main() | void main() | ||
{ | { | ||
//Creating a smoothing 3x3 Gaussian Filter with Standard Deviation 0.7 | |||
cuviCreateFilter(&f,3,3); | |||
f->sigma = 0.7f; | |||
cuviCreateFilterSpecial(f,CUVI_FILTER_GAUSSIAN); | |||
//Image size | |||
CuviSize size = cuviSize(width,height); | |||
//Buffer Images on GPU | //Buffer Images on GPU | ||
CuviImage* gFrame = new CuviImage( | CuviImage* gFrame = new CuviImage(size,8,3); | ||
CuviImage* gimg1 = new CuviImage( | CuviImage* gimg1 = new CuviImage(size,8,1); | ||
CuviImage* gimg2 = new CuviImage( | CuviImage* gimg2 = new CuviImage(size,8,1); | ||
//Region of Interest in the video frame | //Region of Interest in the video frame | ||
Line 62: | Line 75: | ||
do | do | ||
{ | { | ||
//Read a Video Frame and populate GPU image with it | //Read a Video Frame on host 'frame' and populate GPU image with it | ||
gFrame->upload(frame->imageData); | gFrame->upload(frame->imageData,frame->widthStep); | ||
//Converting to Gray Image for computations | //Converting to Gray Image for computations | ||
Line 83: | Line 96: | ||
if(SmoothBeforeSelecting){ | if(SmoothBeforeSelecting){ | ||
//Apply Gaussian Smoothing Filter On Both The Images | //Apply Gaussian Smoothing Filter On Both The Images | ||
cuvi::imageFiltering::imageFilter(gimg1,roi, | cuvi::imageFiltering::imageFilter(gimg1,roi,f); | ||
cuvi::imageFiltering::imageFilter(gimg2,roi, | cuvi::imageFiltering::imageFilter(gimg2,roi,f); | ||
} | } | ||
//Call any Feature Detector on first Frame( KLT | HARRIS | PETER ) | |||
cuvi::computerVision::goodFeaturesToTrack(gimg1,roi,features1,&feature_count, | |||
//Defining feature selection criteria from parameters | |||
CuviFeaturesCriteria feature_criteria = cuviFeaturesCriteria(CUVI_FEATURES_HARRIS, featureQuality, featureMinDistance, blockSize, k); | |||
//Call any Feature Detector on first Frame( KLT | HARRIS | PETER ) | |||
cuvi::computerVision::goodFeaturesToTrack(gimg1,roi,features1,&feature_count,feature_criteria); | |||
//You can also plot the tracked features on the screen | //Defining tracking criteria from tracking parameters | ||
CuviTrackingCriteria tracking_criteria = cuviTrackingCriteria(pyramidLevels, trackingWindow, iterations, residue); | |||
//Track Features Using of Frame#1 onto Frame#2 using KLT Tracker | |||
cuvi::trackFeatures(gimg1,gimg2,features1,features2,feature_count,tracking_criteria ); | |||
//At this point you can indetify whether the selected features in frame one moved in frame two or not | |||
for(int i=0; i<feature_count; i++){ | |||
//True only if the feature has moved from its location | |||
if(FeatureHasMoved(features1[i],features2[i],MovementThreshold)) | |||
//You can also plot the tracked features on the screen | |||
} | |||
}while(video_Frames) | }while(video_Frames) | ||
//Freeing GPU Memory | //Freeing GPU Memory | ||
gFrame | delete gFrame; | ||
gimg1 | delete gimg1; | ||
gimg2 | delete gimg2; | ||
} | } | ||
Line 111: | Line 140: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
|} | |} | ||
{{#ev:vimeo|38484537|500}} | |||
<p>Here's an exact same example applied on a video feed of a webcam</p> | |||
==Demosaic Example== | |||
CUVI demosaic, especially DFPD version is one of the most used and sought after feature of library. The sheer speed of debayering with CUVI linear debayer approach and the perfection in the resultant image in DFPD approach makes it the most demanded function of the library by camera manufacturers and video houses alike. In this example, we'll demonstrate how easy to use CUVI's own demosacing with just few lines of code. | |||
{| | |||
|style="font-size:130%;"| | |||
<syntaxhighlight lang="cpp"> | |||
#include <cuvi.h> | |||
CuviBayerSeq sensorAlignment = CuviBayerSeq::CUVI_BAYER_RGGB; | |||
// 8 bits data in an 8 bit container. Setting this is very important | |||
Cuvi32s containerBits = 8; | |||
Cuvi32s dataBits = 8; | |||
//Load and Upload image to GPU | |||
CuviImage input("D:/lighthouse_8bit_RGGB.tif", CUVI_LOAD_IMAGE_GRAYSCALE_KEEP_DEPTH); | |||
input.setDataBits(dataBits); | |||
//Create container for 3-channel output image | |||
CuviImage output(input.size(), containerBits, 3); | |||
//Perform Demosaic DFPD | |||
cuvi::colorOperations::DFPD(input, output, sensorAlignment); | |||
//Save resultant image to file | |||
cuvi::io::saveImage(output, "D:/lighthouse.tif"); | |||
</syntaxhighlight> | |||
|} | |||
[[File:Lighthouse.jpg|700px]] |
Revision as of 16:44, 27 March 2018
Motion Detection
CUVI library comes with all the image processing essentials that can be used to build countless applications. For example the Computer Vision module of CUVI can be used for motion and intrusion detection in a live video stream and tracking an object of interest throughout series of cameras installed in a premises. The processing pipeline for motion detection goes as follows:
- Read a frame from the camera stream
- Select Strong Features in that Frame using CUVI
- Read next frame
- Track features of first frame in the second frame using CUVI
- Set alarm if motion is detected
The CUVI functions used in this example are goodFeaturesToTrack() and trackFeatures(). For simplicity we have removed the I/O part on host side from the code
|
Here's an exact same example applied on a video feed of a webcam
Demosaic Example
CUVI demosaic, especially DFPD version is one of the most used and sought after feature of library. The sheer speed of debayering with CUVI linear debayer approach and the perfection in the resultant image in DFPD approach makes it the most demanded function of the library by camera manufacturers and video houses alike. In this example, we'll demonstrate how easy to use CUVI's own demosacing with just few lines of code.
|