# Something More for Research

## Explorer of Research #HEMBAD

Lunch: 12.00 PM - 1.00 PM
Dinner: M-Sat 8.30 PM - 9.30 PM,
Sun: 9.30 PM - 11.30 PM
• ## Recent Comments

Error: Twitter did not respond. Please wait a few minutes and refresh this page.

• ## Upcoming Events

No upcoming events

• ## Follow Blog via Email

Join 4,396 other followers

• ## Blog Stats

• 80,503 hits

## CUDA Unified Memory

Posted by Hemprasad Y. Badgujar on October 6, 2015

CUDA is the language of Nvidia GPU’s.  To extract maximum performance from GPU’s, you’ll want to develop applications in CUDA.

CUDA Toolkit is the primary IDE (integrated development environment) for developing CUDA-enabled applications.  The main roles of the Toolkit IDE are to simplify the software development process, maximize software developer productivity, and provide features that enhance GPU performance.  The Toolkit has been steadily evolving in tandem with GPU hardware and currently sits at Version 6.5.

One of the most important features of CUDA 6.5 is Unified Memory (UM).  (UM was actually first introduced in CUDA v.6.0).  CPU host memory and GPU device memory are physically separate entities, connected by a relatively slow PCIe bus.  Prior to v.6.0, data elements shared in both CPU and GPU memory required two copies – one copy in CPU memory and one copy in GPU memory.  Developers had to allocate memory on the CPU, allocate memory on the GPU, and then copy data from CPU to GPU and from GPU to CPU.  This dual data management scheme added complexity to programs, opportunities for the introduction of software bugs, and an excessive focus of time and energy on data management tasks.

UM corrects this.  UM creates a memory pool that is shared between CPU and GPU, with a single memory address space and single pointers accessible to both host and device code.  The CUDA driver and runtime libraries automatically handle data transfers between host and device memory, thus relieving developers from the burden of explicitly managing those data transfers.  UM improves performance by automatically providing data locality on the CPU or GPU, wherever it might be required by the application algorithm.  UM also guarantees global coherency of data on host and device, thus reducing the introduction of software bugs.

Let’s explore some sample code that illustrates these concepts.  We won’t concern ourselves with the function of this algorithm; instead, we’ll just focus on the syntax. (Credit to Nvidia for this C/CUDA template example).

Without Unified Memory

Without Unified Memory

 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 #include  #include  struct DataElement {   char *name;   int value; }; __global__ void Kernel(DataElement *elem) {   printf("On device: name=%s, value=%d\n", elem->name, elem->value;   elem->name[0] = 'd';   elem->value++; } void launch(DataElement *elem) {   DataElement *d_elem;   char *d_name;   int namelen = strlen(elem->name) + 1;   // Allocate memory on GPU   cudaMalloc(&d_elem, sizeofDataElement());   cudaMalloc(&d_name, namelen);   // Copy data from CPU to GPU   cudaMemcpy(d_elem, elem, sizeof(DataElement),      cudaMemcpyHostToDevice);   cudaMemcpy(d_name, elem->name, namelen, cudaMemcpyHostToDevice);   cudaMemcpy(&(d_elem->name), &d_name, sizeof(char*),      cudaMemcpyHostToDevice);   // Launch kernel   Kernel<<< 1, 1 >>>(d_elem);   // Copy data from GPU to CPU   cudaMemcpy(&(elem->value), &(d_elem->value), sizeof(int),      cudaMemcpyDeviceToHost);   cudaMemcpy(elem->name, d_name, namelen, cudaMemcpyDeviceToHost);   cudaFree(d_name);   cudaFree(d_elem); } int main(void) {   DataElement *e;   // Allocate memory on CPU   e = (DataElement*)malloc(sizeof(DataElement));   e->value = 10;   // Allocate memory on CPU   e->name = (char*)malloc(sizeof(char) * (strlen("hello") + 1));   strcpy(e->name, "hello");   launch(e);   printf("On host: name=%s, value=%d\n", e->name, e->value);   free(e->name);   free(e);   cudaDeviceReset(); }

Note these key points:

• L51,55: Allocate memory on CPU
• L24,25: Allocate memory on GPU
• L28-32: Copy data from CPU to GPU
• L35: Run kernel
• L38-40: Copy data from GPU to CPU

With Unified Memory

 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 #include  #include  struct DataElement {   char *name;   int value; }; __global__ void Kernel(DataElement *elem) {   printf("On device: name=%s, value=%d\n", elem->name, elem->value;   elem->name[0] = 'd';   elem->value++; } void launch(DataElement *elem) {   // Launch kernel   Kernel<<< 1, 1 >>>(elem);   cudaDeviceSynchronize(); } int main(void) {   DataElement *e;   // Allocate unified memory on CPU and GPU   cudaMallocManaged((void**)&e, sizeof(DataElement));   e->value = 10;   // Allocate unified memory on CPU and GPU   cudaMallocManaged((void**)&(e->name), sizeof(char) *      (strlen("hello") + 1) );   strcpy(e->name, "hello");   launch(e);   printf("On host: name=%s, value=%d\n", e->name, e->value);   cudaFree(e->name);   cudaFree(e);   cudaDeviceReset(); } 

Note these key points:

• L28, 32, 33: Allocate unified memory on CPU and GPU
• L19: Run kernel

With UM, memory is allocated on the CPU and GPU in a single address space and managed with a single pointer.  Note how the “malloc’s” and “cudaMalloc’s” are condensed into single calls to cudaMallocManaged().  Furthermore, explicit cudaMemcpy() data transfers between CPU and GPU are eliminated, as the CUDA runtime handles these transfers automatically in the background. Collectively these actions simplify code development, code maintenance, and data management.

As software project managers, we like UM for the productivity enhancements it provides for our software development teams.  It improves software quality, reduces coding time, effort and cost, and enhances overall performance. As software engineers, we like UM because of reduced coding effort and the fact that we can focus time and effort on writing CUDA kernel code, where all the parallel performance comes from, instead of spending time on memory management tasks.  Unified Memory is major step forward in GPU programming.

## CUDA Random Numbers

Posted by Hemprasad Y. Badgujar on October 3, 2015

### CUDA Random Example

In order to use cuRAND, we need to add two include files into our program:

#include &lt;curand.h&gt;
#include &lt;curand_kernel.h&gt;


cuRAND uses a curandState_t type to keep track of the state of the random sequence. The normal C rand function also has a state, but it is global, and hidden from the programmer. This makes rand not thread-safe, but easier to use.

A curandState_t object must be initialized with a call to curand_init which has the following parameters:

• seed: The seed determines the beginning point of the sequence of random numbers.
• sequence: The sequence number is another seed-like value. It is used so that, if all cores have the same seed, but different sequence numbers, then they will get different random values.
• offset: The amount we skip ahead in the random sequence. This can be zero.
• state: A pointer to the curandState_t object to initialize.

Once we have an initialized curandState_t object, we can get random numbers with the curand function which takes a pointer to a curandState_t object and returns to us a random unsigned integer.

The following program uses these functions to generate random numbers:

#include <unistd.h>
#include <stdio.h>

/* we need these includes for CUDA's random number stuff */
#include <curand.h>
#include

#define MAX 100

/* this GPU kernel function calculates a random number and stores it in the parameter */
__global__ void random(int* result) {
/* CUDA's random number library uses curandState_t to keep track of the seed value
we will store a random state for every thread  */
curandState_t state;

/* we have to initialize the state */
curand_init(0, /* the seed controls the sequence of random values that are produced */
0, /* the sequence number is only important with multiple cores */
0, /* the offset is how much extra we advance in the sequence for each call, can be 0 */
&state);

/* curand works like rand - except that it takes a state as a parameter */
*result = curand(&state) % MAX;
}

int main( ) {
/* allocate an int on the GPU */
int* gpu_x;
cudaMalloc((void**) &gpu_x, sizeof(int));

/* invoke the GPU to initialize all of the random states */
random<<<1, 1>>>(gpu_x);

/* copy the random number back */
int x;
cudaMemcpy(&x, gpu_x, sizeof(int), cudaMemcpyDeviceToHost);

printf("Random number = %d.\n", x);

/* free the memory we allocated */
cudaFree(gpu_x);

return 0;
}


When run, this program produces the exact same random number each time. This is because the seed passed in was 0. In order to get a different random number each time, we can pass in the current time as the seed.


#include <unistd.h>
#include <stdio.h>

/* we need these includes for CUDA's random number stuff */

#include
#include

#define MAX 100

/* this GPU kernel function calculates a random number and stores it in the parameter */
__global__ void random(unsigned int seed, int* result) {
/* CUDA's random number library uses curandState_t to keep track of the seed value
we will store a random state for every thread  */
curandState_t state;

/* we have to initialize the state */
curand_init(seed, /* the seed controls the sequence of random values that are produced */
0, /* the sequence number is only important with multiple cores */
0, /* the offset is how much extra we advance in the sequence for each call, can be 0 */
&state);

/* curand works like rand - except that it takes a state as a parameter */
*result = curand(&state) % MAX;
}

int main( ) {
/* allocate an int on the GPU */
int* gpu_x;
cudaMalloc((void**) &gpu_x, sizeof(int));

/* invoke the GPU to initialize all of the random states */
random<<<1, 1>>>(time(NULL), gpu_x);

/* copy the random number back */
int x;
cudaMemcpy(&x, gpu_x, sizeof(int), cudaMemcpyDeviceToHost);

printf("Random number = %d.\n", x);

/* free the memory we allocated */
cudaFree(gpu_x);

return 0;
}


### Using Random Numbers Across Cores

If we want to get random numbers in multiple GPU cores, then we would need each core to have its own curandState_t.

If we want each run of the program to produce different sequences of random numbers, then we would need to set the seed to the current time.

However, now we would likely have each core get the same sequence of numbers. This is probably undesirable. To avoid it, we set the sequence parameter to the thread’s ID.

This way, each thread will have a different stream of random numbers, which will also be different each time the program is run.

The following program illustrates this by creating N curandState_t objects, then launching a GPU kernel to get N random numbers from them, in parallel.

#include <unistd.h>
#include <stdio.h>

/* we need these includes for CUDA's random number stuff */
#include
#include

#define N 25

#define MAX 100

/* this GPU kernel function is used to initialize the random states */
__global__ void init(unsigned int seed, curandState_t* states) {

/* we have to initialize the state */
curand_init(seed, /* the seed can be the same for each core, here we pass the time in from the CPU */
blockIdx.x, /* the sequence number should be different for each core (unless you want all
cores to get the same sequence of numbers for some reason - use thread id! */
0, /* the offset is how much extra we advance in the sequence for each call, can be 0 */
&states[blockIdx.x]);
}

/* this GPU kernel takes an array of states, and an array of ints, and puts a random int into each */
__global__ void randoms(curandState_t* states, unsigned int* numbers) {
/* curand works like rand - except that it takes a state as a parameter */
numbers[blockIdx.x] = curand(&states[blockIdx.x]) % 100;
}

int main( ) {
/* CUDA's random number library uses curandState_t to keep track of the seed value
we will store a random state for every thread  */
curandState_t* states;

/* allocate space on the GPU for the random states */
cudaMalloc((void**) &states, N * sizeof(curandState_t));

/* invoke the GPU to initialize all of the random states */
init<<<n, 1="">>>(time(0), states);

/* allocate an array of unsigned ints on the CPU and GPU */
unsigned int cpu_nums[N];
unsigned int* gpu_nums;
cudaMalloc((void**) &gpu_nums, N * sizeof(unsigned int));

/* invoke the kernel to get some random numbers */
randoms<<<n, 1="">>>(states, gpu_nums);

/* copy the random numbers back */
cudaMemcpy(cpu_nums, gpu_nums, N * sizeof(unsigned int), cudaMemcpyDeviceToHost);

/* print them out */
for (int i = 0; i < N; i++) {
printf("%u\n", cpu_nums[i]);
}

/* free the memory we allocated for the states and numbers */
cudaFree(states);
cudaFree(gpu_nums);

return 0;
}


This program is also the first to use multiple GPU kernel functions.

### Random Distributions

In addition to the curand function which, together with modular arithmetic, can return to us random integers from any range we wish, cuRAND provides functions to get floating point numbers from different distributions:

__device__ float curand_uniform (curandState_t *state)

__device__ float curand_normal (curandState_t *state)


curand_uniform returns a random number between 0.0 and 1.0 following a uniform distribution. This means that all floating point numbers in that range are equally likely to be produced.

curand_normal also returns a random number between 0.0 and 1.0, but it follows a normal distribution, meaning that the number 0.5 is more likely to be produced than numbers near 0.0 or 1.0. Normal distributions would be important for modelling many natural phenomenon accurately.

Posted in CUDA TUTORIALS, GPU (CUDA), PARALLEL | Tagged: | Leave a Comment »

## Bilateral Filtering

Posted by Hemprasad Y. Badgujar on September 14, 2015

Popular Filters

When smoothing or blurring images (the most popular goal of smoothing is to reduce noise), we can use diverse linear filters, because linear filters are easy to achieve, and are kind of fast, the most used ones are Homogeneous filter, Gaussian filter, Median filter, et al.

When performing a linear filter, we do nothing but output pixel’s value g(i,j)  which is determined as a weighted sum of input pixel values f(i+k, j+l):

g(i, j)=SUM[f(i+k, j+l) h(k, l)];

in which, h(k, l)) is called the kernel, which is nothing more than the coefficients of the filter.

Homogeneous filter is the most simple filter, each output pixel is the mean of its kernel neighbors ( all of them contribute with equal weights), and its kernel K looks like:

Gaussian filter is nothing but using different-weight-kernel, in both x and y direction, pixels located in the middle would have bigger weight, and the weights decrease with distance from the neighborhood center, so pixels located on sides have smaller weight, its kernel K is something like (when kernel is 5*5):

Median filter is something that replace each pixel’s value with the median of its neighboring pixels. This method is great when dealing with “salt and pepper noise“.

Bilateral Filter

By using all the three above filters to smooth image, we not only dissolve noise, but also smooth edges, which make edges less sharper, even disappear. To solve this problem, we can use a filter called bilateral filter, which is an advanced version of Gaussian filter, it introduces another weight that represents how two pixels can be close (or similar) to one another in value, and by considering both weights in image,  Bilateral filter can keep edges sharp while blurring image.

Let me show you the process by using this image which have sharp edge.

Say we are smoothing this image (we can see noise in the image), and now we are dealing with the pixel at middle of the blue rect.

Left-above picture is a Gaussian kernel, and right-above picture is Bilateral filter kernel, which considered both weight.

We can also see the difference between Gaussian filter and Bilateral filter by these pictures:

Say we have an original image with noise like this

By using Gaussian filter, the image is smoother than before, but we can see the edge is no longer sharp, a slope appeared between white and black pixels.

However, by using Bilateral filter, the image is smoother, the edge is sharp, as well.

OpenCV code

It is super easy to make these kind of filters in OpenCV:

 1 //Homogeneous blur:
 2 blur(image, dstHomo, Size(kernel_length, kernel_length), Point(-1,-1));
 3 //Gaussian blur:
 4 GaussianBlur(image, dstGaus, Size(kernel_length, kernel_length), 0, 0);
 5 //Median blur:
 6 medianBlur(image, dstMed, kernel_length);
 7 //Bilateral blur:
 8 bilateralFilter(image, dstBila, kernel_length, kernel_length*2, kernel_length/2);

and for each function, you can find more details in OpenCV Documentation

Test Images

Glad to use my favorite Van Gogh image :

From left to right: Homogeneous blur, Gaussian blur, Median blur, Bilateral blur.

(click iamge to view full size version :p )

kernel length = 3:

kernel length = 9:

kernel length = 15:

kernel length = 23:

kernel length = 31:

kernel length = 49:

kernel length = 99:

## Basic drawing examples of OpenCV

Posted by Hemprasad Y. Badgujar on July 20, 2015

### Drawing a line

void line(Mat& img, Point pt1, Point pt2, const Scalar& color, int thickness=1, int lineType=8, int shift=0)
Parameters:

• img – Image.
• pt1 – First point of the line segment.
• pt2 – Second point of the line segment.
• color – Line color.
• thickness – Line thickness.
• lineType – Type of the line:
• 8 (or omitted) – 8-connected line.
• 4 – 4-connected line.
• CV_AA – antialiased line.
• shift – Number of fractional bits in the point coordinates.

### Example 1: Drawing a line

 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 #include  #include  using namespace cv; int main( ) {       // Create black empty images   Mat image = Mat::zeros( 400, 400, CV_8UC3 );      // Draw a line    line( image, Point( 15, 20 ), Point( 70, 50), Scalar( 110, 220, 0 ),  2, 8 );   imshow("Image",image);   waitKey( 0 );   return(0); }

### Drawing a Circle

void circle(Mat& img, Point center, int radius, const Scalar& color, int thickness=1, int lineType=8, int shift=0)
Parameters:

• img – Image where the circle is drawn.
• center – Center of the circle.
• radius – Radius of the circle.
• color – Circle color.
• thickness – Thickness of the circle outline, if positive. Negative thickness means that a filled circle is to be drawn.
• lineType – Type of the circle boundary. See the line() description.
• shift – Number of fractional bits in the coordinates of the center and in the radius value.

The function circle draws a simple or filled circle with a given center and radius.

### Example 2: Drawing a Circle

 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 #include  #include  using namespace cv; int main( ) {       // Create black empty images   Mat image = Mat::zeros( 400, 400, CV_8UC3 );      // Draw a circle    circle( image, Point( 200, 200 ), 32.0, Scalar( 0, 0, 255 ), 1, 8 );   imshow("Image",image);   waitKey( 0 );   return(0); }

### Drawing an Ellipse

void ellipse(Mat& img, Point center, Size axes, double angle, double startAngle, double endAngle, const Scalar& color, int thickness=1, int lineType=8, int shift=0)
Parameters:

• img – Image.
• center – Center of the ellipse.
• axes – Length of the ellipse axes.
• angle – Ellipse rotation angle in degrees.
• startAngle – Starting angle of the elliptic arc in degrees.
• endAngle – Ending angle of the elliptic arc in degrees.
• box – Alternative ellipse representation via RotatedRect or CvBox2D. This means that the function draws an ellipse inscribed in the rotated rectangle.
• color – Ellipse color.
• thickness – Thickness of the ellipse arc outline, if positive. Otherwise, this indicates that a filled ellipse sector is to be drawn.
• lineType – Type of the ellipse boundary. See the line() description.
• shift – Number of fractional bits in the coordinates of the center and values of axes.

The functions ellipse with less parameters draw an ellipse outline, a filled ellipse, an elliptic arc, or a filled ellipse sector. A piecewise-linear curve is used to approximate the elliptic arc boundary.

If you use the first variant of the function and want to draw the whole ellipse, not an arc, passstartAngle=0 and endAngle=360.

### Example 3: Drawing an Ellipse

 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 #include  #include  using namespace cv; int main( ) {       // Create black empty images   Mat image = Mat::zeros( 400, 400, CV_8UC3 );      // Draw a ellipse    ellipse( image, Point( 200, 200 ), Size( 100.0, 160.0 ), 45, 0, 360, Scalar( 255, 0, 0 ), 1, 8 );   ellipse( image, Point( 200, 200 ), Size( 100.0, 160.0 ), 135, 0, 360, Scalar( 255, 0, 0 ), 10, 8 );   ellipse( image, Point( 200, 200 ), Size( 150.0, 50.0 ), 135, 0, 360, Scalar( 0, 255, 0 ), 1, 8 );   imshow("Image",image);   waitKey( 0 );   return(0); }

### Drawing a Rectangle

void rectangle(Mat& img, Point pt1, Point pt2, const Scalar& color, int thickness=1, int lineType=8, int shift=0)
Parameters:

• img – Image.
• pt1 – Vertex of the rectangle.
• pt2 – Vertex of the rectangle opposite to pt1 .
• rec – Alternative specification of the drawn rectangle.
• colorRectangle color or brightness (grayscale image).
• thickness – Thickness of lines that make up the rectangle. Negative values, likeCV_FILLED , mean that the function has to draw a filled rectangle.
• lineType – Type of the line. See the line() description.
• shift – Number of fractional bits in the point coordinates.

### Example 4: Drawing a Rectangle

 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 #include  #include  using namespace cv; int main( ) {       // Create black empty images   Mat image = Mat::zeros( 400, 400, CV_8UC3 );      // Draw a rectangle ( 5th argument is not -ve)   rectangle( image, Point( 15, 20 ), Point( 70, 50), Scalar( 0, 55, 255 ), +1, 4 );   imshow("Image1",image);   // Draw a filled rectangle ( 5th argument is -ve)   rectangle( image, Point( 115, 120 ), Point( 170, 150), Scalar( 100, 155, 25 ), -1, 8 );   imshow("Image2",image);   waitKey( 0 );   return(0); }

### Drawing a Filled Polygon

void fillPoly(Mat& img, const Point** pts, const int* npts, int ncontours, const Scalar& color, int lineType=8, int shift=0, Point offset=Point() )
Parameters:

• img – Image.
• pts – Array of polygons where each polygon is represented as an array of points.
• npts – Array of polygon vertex counters.
• ncontours – Number of contours that bind the filled region.
• color – Polygon color.
• lineType – Type of the polygon boundaries. See the line() description.
• shift – Number of fractional bits in the vertex coordinates.
• offset – Optional offset of all points of the contours.

The function fillPoly fills an area bounded by several polygonal contours. The function can fill complex areas, for example, areas with holes, contours with self-intersections (some of their parts), and so forth.

### Example 4: Drawing a Filled Polygon

 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 #include  #include  using namespace cv; int main( ) {       // Create black empty images   Mat image = Mat::zeros( 400, 400, CV_8UC3 );      int w=400;   // Draw a circle    /** Create some points */   Point rook_points[1][20];   rook_points[0][0] = Point( w/4.0, 7*w/8.0 );   rook_points[0][1] = Point( 3*w/4.0, 7*w/8.0 );   rook_points[0][2] = Point( 3*w/4.0, 13*w/16.0 );   rook_points[0][3] = Point( 11*w/16.0, 13*w/16.0 );   rook_points[0][4] = Point( 19*w/32.0, 3*w/8.0 );   rook_points[0][5] = Point( 3*w/4.0, 3*w/8.0 );   rook_points[0][6] = Point( 3*w/4.0, w/8.0 );   rook_points[0][7] = Point( 26*w/40.0, w/8.0 );   rook_points[0][8] = Point( 26*w/40.0, w/4.0 );   rook_points[0][9] = Point( 22*w/40.0, w/4.0 );   rook_points[0][10] = Point( 22*w/40.0, w/8.0 );   rook_points[0][11] = Point( 18*w/40.0, w/8.0 );   rook_points[0][12] = Point( 18*w/40.0, w/4.0 );   rook_points[0][13] = Point( 14*w/40.0, w/4.0 );   rook_points[0][14] = Point( 14*w/40.0, w/8.0 );   rook_points[0][15] = Point( w/4.0, w/8.0 );   rook_points[0][16] = Point( w/4.0, 3*w/8.0 );   rook_points[0][17] = Point( 13*w/32.0, 3*w/8.0 );   rook_points[0][18] = Point( 5*w/16.0, 13*w/16.0 );   rook_points[0][19] = Point( w/4.0, 13*w/16.0) ;   const Point* ppt[1] = { rook_points[0] };   int npt[] = { 20 };   fillPoly( image, ppt, npt, 1, Scalar( 255, 255, 255 ), 8 );   imshow("Image",image);   waitKey( 0 );   return(0); }

### Putting Text in image

putText renders the specified text string in the image.

void putText(Mat& img, const string& text, Point org, int fontFace, double fontScale, Scalar color, int thickness=1, int lineType=8, bool bottomLeftOrigin=false )
Parameters:

• img – Image.
• text – Text string to be drawn.
• org – Bottom-left corner of the text string in the image.
• fontFace – Font type. One of FONT_HERSHEY_SIMPLEX, FONT_HERSHEY_PLAIN,FONT_HERSHEY_DUPLEX, FONT_HERSHEY_COMPLEX, FONT_HERSHEY_TRIPLEX,FONT_HERSHEY_COMPLEX_SMALL, FONT_HERSHEY_SCRIPT_SIMPLEX, orFONT_HERSHEY_SCRIPT_COMPLEX, where each of the font ID’s can be combined withFONT_HERSHEY_ITALIC to get the slanted letters.
• fontScale – Font scale factor that is multiplied by the font-specific base size.
• color – Text color.
• thickness – Thickness of the lines used to draw a text.
• lineType – Line type. See the line for details.
• bottomLeftOrigin – When true, the image data origin is at the bottom-left corner. Otherwise, it is at the top-left corner.

### Example 5: Putting Text in image

 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 #include  #include  using namespace cv; int main( ) {    // Create black empty images   Mat image = Mat::zeros( 400, 400, CV_8UC3 );      putText(image, "Hi all...", Point(50,100), FONT_HERSHEY_SIMPLEX, 1, Scalar(0,200,200), 4);   imshow("Image",image);   waitKey( 0 );   return(0); }

Posted in Mixed | Tagged: | Leave a Comment »

## cppconlib: A C++ library for working with the Windows console

Posted by Hemprasad Y. Badgujar on July 20, 2015

cppconlib is built with C++11 features and requires Visual Studio 2012 or newer. The library is available in a single header called conmanip.h and provides a set of helper classes, functions and constants for manipulating a Windows console (using the Windows console functions). The library features the following components:

• console_context<T>: represents a context object for console operations; its main purpose is restoring console settings; typedefs for the three consoles are available (console_in_context, console_out_context and console_err_context)
• console<T>: represents a console objects providing operations such as changing the foreground and background colors, the input mode, screen buffer size, title, and others; typedefs for the three consoles are available (console_in, console_out and console_err)
• manipulating functions that can be used with cout/wcout and cin/wcin: settextcolor()/restoretextcolor(), setbgcolor()/restorebgcolor(), setcolors(),setmode()/clearmode(), setposx()/setposy()/setpos().

The library can be downloaded from here. Detailed documentation is available here.

### Examples

The following example prints some text in custom colors and then reads text in a different set of colors.

The following code prints a rhomb to the console:

For more details and updates check the project at codeplex: https://cppconlib.codeplex.com.

UPDATE: A NuGet package for cppconlib is available.

## OpenCV: Color-spaces and splitting channels

Posted by Hemprasad Y. Badgujar on July 18, 2015

### Conversion between color-spaces

Our goal here is to visualize each of the three channels of these color-spaces: RGB, HSV, YCrCb and Lab. In general, none of them are absolute color-spaces and the last three (HSV, YCrCb and Lab) are ways of encoding RGB information. Our images will be read in BGR (Blue-Green-Red), because of OpenCV defaults. For each of these color-spaces there is a mapping function and they can be found at OpenCV cvtColor documentation.
One important point is: OpenCV imshow() function will always assume that the Mat shown is in BGR color-space. Which means, we will always need to convert back to see what we want. Let’s start.

OpenCV Program: Split Channels (356 downloads )

#### HSV

While in BGR, an image is treated as an additive result of three base colors (blue, green and red), HSV stands for Hue, Saturation and Value (Brightness). We can say that HSV is a rearrangement of RGB in a cylindrical shape. The HSV ranges are:

• 0 > H > 360 ⇒ OpenCV range = H/2 (0 > H > 180)
• 0 > S > 1 ⇒ OpenCV range = 255*S (0 > S > 255)
• 0 > V > 1 ⇒ OpenCV range = 255*V (0 > V > 255)

#### YCrCb or YCbCr

It is used widely in video and image compression schemes. The YCrCb stands for Luminance (sometimes you can see Y’ as luma), Red-difference and Blue-difference chroma components. The YCrCb ranges are:

• 0 > Y > 255
• 0 > Cr > 255
• 0 > Cb > 255

#### L*a*b

In this color-opponent space, L stands for the Luminance dimension, while a and b are the color-opponent dimensions. The Lab ranges are:

• 0 > L > 100 ⇒ OpenCV range = L*255/100 (1 > L > 255)
• -127 > a > 127 ⇒ OpenCV range = a + 128 (1 > a > 255)
• -127 > b > 127 ⇒ OpenCV range = b + 128 (1 > b > 255)

### Splitting channels

All the color-spaces mentioned above were constructed using three channels (dimensions). It is a good exercise to visualize each of these channels and realize what they really store, because when I say that the third channel of HSV stores the brightness, what do you expect to see? Remember: a colored image is made of three-channels (in our cases) and when we see each of them separately, what do you think the output will be? If you said a grayscale image, you are correct! However, you might have seen these channels as colored images out there. So, how? For that, we need to choose a fixed value for the other two channels. Let’s do this!
To visualize each channel with color, I used the same values used on the Slides 53 to 65 from CS143, Lecture 03 from Brown University.

RGB or BGR

HSV

YCrCb or YCbCr

Lab or CIE Lab

## Bulk Rename Utility

Posted by Hemprasad Y. Badgujar on July 18, 2015

These file rename software let you rename multiple files easily. All these file rename software are completely free and can be downloaded to Windows PC. These file rename softwareoffer various features, like: rename multiple files at once,rename files as well as folders including sub-folders, can add, remove, replace strings to file names, can copy and rename, move and rename files, supports all types of files (including images, audio/video, office documents etc.), rename files based upon their EXIF data or meta data, and more. Check out this list of free file rename software and find out which you like best.

## File Renamer Basic

File Renamer Basic is a simple yet powerful program to rename files, folders, and MP3 files easily. You can use its filename filter to easily narrow down your search for specific types of files. You can remove x number of characters starting from x character. You can find and replace text also. Apart from its renaming capabilities, it also has a ID3v1 and ID3v2 tag editor.

## Flexible Renamer

Flexible Renamer is a free and easy to use software for renaming files and folders. You can rename files and folders in single or in batches. It doesn’t require installation as it is a portable application. You can use its simple or advanced rename method to rename your files and folders. You can copy and rename, move and rename, move to recycle bin and can use other various methods too. It supports wildcards also when renaming.

Advanced Renamer is a free software for renaming files or folders. It uses various methods for creating the new names. It can create new file names by adding, removing, replacing, giving new name based upon the file information, or changing case. You can test the batch settings before you start renaming. It is also available in portable version.

## BatchRename Free Edition

BatchRename Free is a free files and folders renaming software. It uses two steps to rename files and folders. In step one you can add files and folders to rename and in second step you can set rules for renaming according to your requirements. It has various predefined rules for various types of files. It has some image editing features also, like change format, flip, rotate, resize, shrink etc. You can preview renaming. It installs and uninstalls easily.

## Bulk Rename Utility

Bulk Rename Utility is a free utility to rename files and folders with flexible criteria. It can process sub folders, can add date stamps, auto numbers, search and replace, change time stamps etc. It offers 13 primary functions to rename. It can handle file attributes, metadata, and sophisticated regular expressions. You can preview file names before you actually start renaming. This software is for power users.

## Batch File Modifier

Batch File Modifier is a multipurpose software and it also has the functionality of renaming files and folders. It has a wizard like interface. You can set the naming options from the options window and can use the various tabs according to your requirement of renaming. You can add prefix or suffix to file names. You can preview file names also in this window. You can undo the rename process also.

## XnView

XnView is actually a multi format graphics browser, viewer, and converter, but it also has the functionality of renaming files. It has an Explorer like interface. You can browse for folder whose files have to be renamed and select the files to be renamed. Select the batch rename option from the context menu. Set the rename options from the interface according to your choice. You can view the new name of files in real time. On satisfying the new names start the rename process by clicking on Rename button.

## ReNamer

ReNamer is a simple file renaming tool. It lets you rename files and folders according to standard renaming procedures, including case changes, prefixes, suffixes, replacements, adding number sequences etc. Also supports changing of file extensions. You can add the rules before you start renaming. This software is for beginners as well as for advance users.

## IrfanView

IrfanView is a simple, small, fast, compact and innovative free graphic viewer software and also has the functionality of renaming files. You can use it to rename files from any specified folder and its subfolders. You can set the rename options before you start renaming. You can also preview the batch rename results. You can see the errors and warnings in the preview mode. It is a very simple and easy to use software to rename the files.

## Rename It

Rename It is a simple file renaming utility specifically designed for new computer users. It lets you rename a file or a file extension easily. It has an option of massive rename which lets you rename multiple files or extensions easily. If there is a common text in the name of files, it can be easily renamed with the help of it.

## Effective File Search

Effective File Search is actually a file searching utility and also has a function of renaming files. You can use it to rename the filenames to either lowercase or uppercase only. To use it, first browse for a folder from which files have to be renamed by using its browse button. You can include sub directories also in the search. Now search for all files or for any particular format. Select the files from the results and select rename files options from the Actions menu.

## Ken Rename

Ken Rename is a free batch file renaming utility. It has various configuration options to rename files. Some of its features include: filter files with wildcard, convert to lowercase or uppercase, replace particular text from names, insert digit and increment options, EXIF support etc. You can view the real time preview of renamed files before actually renaming. It is for beginners as well as for advance users.

## PhotoRenamer

PhotoRenamer is a free software which lets you rename your digital photos according to the date and the time you took the pictures. It uses date and time or EXIF Data for renaming or you can use renaming masks. Renaming masks are format specifications stings for e.g. day, month, year, hour, min, sec, photo number and free text. Note: If you choose file selection filter as ., then you can rename any type of file according to renaming mask you use.

## Image Renaming

Image Renaming is a free software to rename image files. You can rename image files based on date and time criteria. You can choose from various predefined formats or can customize your own. It comes as a ZIP file and you can extract it to the desired location and run it. It doesn’t require installation and can be used as a portable software. It is very small in size.

## Panda Batch File Renamer

Panda Batch File Renamer is a free file renaming software. It lets you rename files in batch mode. You can choose from various rename options. You can use its insert, replace, remove, and other categories of renaming options. It shows the current file name and final file names side by side. You can add multiple renaming options and they can be queued. It stores the history of changes so you can undo the rename process if required.

## Aoao Batch Rename

Aoao Batch Rename is free and easy to use file renaming software. You can rename multiple files at once. You can rename all file formats. It is good for renaming image files. You can set the file names with increasing alphabet or digit. This software can be used for simple renaming tasks.

## RenPhoric

RenPhoric is a simple and easy to use batch renaming software. It is good for search and replace text in the file names. You can include subdirectories too for renaming files. It allows you to use regular expressions for renaming process. It is a great choice for you to batch rename images, songs, or any other files that are big in numbers.

## Rename JPEG Files

Rename JPEG Files is a free software to rename JPG files in bulk quantity. It uses predefined file naming formats. You can drag and drop files to its window or specify a target directory that contains JPG files. It also displays the information about JPG files selected, such as name, creation date, resolution etc. It shows the file names before and after side by side. You can build the name format or use the default format.

## File Renamer

File Renamer is a free and handy software to rename multiple files at once. You can batch rename files, add or remove text strings from file names, can change file extensions, add numbers sequentially to file names, change to upper case or lowercase, trim characters etc. It also has an undo option for last rename process. It doesn’t require installation and can be used as a portable software.

## FMS File Renamer

FMS File Renamer is a simple and useful tool to rename files. It has various features to rename files. You can try various combinations for renaming the files. You can add strings to prefix, suffix, or at a position you choose in the resultant file names. You can delete, replace, change case (upper of lower), move/copy etc. in one go. You can preview every step by clicking green check mark. The program is suitable for any type of user (newbie or advance).

## Rename Master

Rename Master is a free software to rename multiple files with few clicks. It is a simple tool to rename multiple files easily. It has 15 types of rename options and you can configure each of them separately. It lets you add, remove, or replace strings to file names easily. You can rename folders too with this utility. It also supports scripts to save the renaming options. It doesn’t require installation.

## Batch Rename .EXE

Batch Rename .EXE is a free software to rename multiple files at once. It can rename files in four easy steps in a wizard like interface. You can add files or folders to rename in step one. In step two set the rules for renaming. You can preview the results in the step three and finally rename them in step four. It can include the metadata in the names of files for renaming.

## A.F.5 Rename your files

A.F.5 Rename your files is a free software to rename files easily. It has various features including drag & drop support, preview before renaming, undo last rename action, create batch program files, save rename settings, import filenames from a text file. You can apply multiple types of values to the file names for renaming like text string, size, digit counter, metadata etc. You can undo the last rename changes also by clicking again on rename button.

## File Renamer

File Renamer is a free software for renaming multiple files at once. It can be used to rename images as well as all types of files. You can use file mask to filter files of specific type (for e.g. *.png). You can set the new name with incremental digit. It also has an option to move the renamed files to a different folder.

## Fast File Renamer

Fast File Renamer is a free software to rename files based upon criteria you choose. You can replace, remove, or insert strings to file names. It has a simulate function which lets you preview the files before you actually rename. When satisfied with the new name, click undo simulate button and click perform rename button to rename files. It can be used as portable software.

## Lupas Rename

Lupas Rename is a free and easy to use software to rename multiple files. You can rename folders too. Files in the sub directories can also be renamed. It also supports undo last rename operation. You can filter files for any particular type using wildcards. You can apply multiple options together (name, extension, and auto number) in the rename process. It shows the real time preview of results.

## Wild Rename

Wild Rename is a very simple and easy to use file renaming utility. You can perform the task of renaming files with regular expressions. It doesn’t require installation and can be used as a portable software. It can help you to rename file names by converting lower case, upper case, or normal case. You can add strings to file names, replace specific text from file names, add counters etc.

## Siren

Siren is a free, small but powerful renaming tool for Windows. It is for normal users as well as for power users. You can use it to rename multiple files and folders. It uses expressions for renaming process. You can build your own customized naming expression by using help. It doesn’t require installation and can be used as a portable software.

## MP3 Rename

MP3 Rename is a free utility to rename MP3 files easily. It can rename MP3 files according to rules that you specify. You can replace the text with your text from the names of MP3 files. It doesn’t require installation and can be used as a portable software. You can add ID3 v2 tags to file names. You can move files into folders according to artist name also. It is a good software to rename MP3 files.

## Ant Renamer

Ant Renamer is a very useful multiple files and folders renaming software. It can rename multiple files, folders with sub-folders and sub-files. It can also rename multiple strings from the file and folder name. Actually, this software provides dozens of file renaming features, some of them are: Move string, String insertion, Change case, Use date & time, Enumeration, etc. This small size portable software is one of the best file renaming software.

## AS-File Renamer

AS-File Renamer is a free software for renaming files. It renames files by providing serial numbers to them. Suppose you capture a snapshot with your camera. Then you can rename the snapshots as abc 1, abc 2, abc 3. If you want to rename your files according to serial numbers then you can try out this freeware.

## LeCase

LeCase is a free and handy file renamer software for your computer. With the help of this freeware you can easily rename all files in a particular directory to lowercase names or uppercase names. By using this freeware you can also rename your picture files in a directory by specifying various numbers to it. e.g x1, x2, x3 etc.

## File Renamex

File Renamex is a free file renamer software to rename files quickly. With the help of this freeware you can rename files in a easy manner. You can rename any type of file e.g. video, audio, picture, document etc. This freeware lets you do file renaming in bulk. It will rename files as per numbering format and prefix.

## KuKnet FileRenamer

KuKnet FileRenamer is a free software for renaming multiple files. It is a powerful tool for renaming files. You can add files or folders by click of a button or by drag and drop to its window. It shows the preview of image files. You can set rules for renaming files and can save them for future use. You can use search and replace, numeration, add file size, date/time, ID3 tag etc. to rename file names. It comes as a single executable and doesn’t require installation.

## EXIF Image Renamer

EXIF Image Renamer is a simple tool for renaming image files based upon their EXIF data. You can select the folder with images to rename by browsing for its location through the program interface. It does not have preview facility so new file names will change according to EXIF data present. It renames the images in sub folders too.

## Batch Rename

Batch Rename is an easy to use but powerful renaming tool for Windows. It lets you rename files and folders according to the rules you set. You can add single rule or combine multiple rules for renaming. For e.g. you can prefix or suffix any text to file names, add counter at specific position, remove strings etc. to the file names. You can also preview the file names before renaming.

## MP3 Renamer

MP3 Renamer is a free tool for renaming large amount of MP3 files. It has various predefined presets for renaming MP3 files like remove extra hyphens, change to sentence case, remove URLs, remove dots, change to upper case etc. You can rename MP3 files based upon their ID3 tags values also. It has a inbuilt MP3 player also.

## Tiny Renamer

Tiny Renamer is a very small and easy to use file renaming utility. You can rename multiple files easily. You can shorten long file names, use simple regular expression or advance regular expression for renaming. You can rename file extension too with the help of it. It has a replace and replace with text box in its main window. It is a good choice for renaming multiple MP3 files.

## JFRenamer

JFRenamer is a free file and folder renaming software. It lets you rename the files and folders according to rules you set. You can add multiple rules to the list for renaming. You can configure each rule separately according to the requirement. You can set various rules like change case, replace, delete, insert, if/else etc. The software is written in JAVA and JAVA must be installed on the system to use it.

## Bica File Renamer

Bica File Renamer is a simple and easy to use file renaming utility. It lets you rename files and folders with few clicks. You can apply many different rename options like search and replace, change case, sequential numbering, insert, remove, date/time etc. It is small in size and doesn’t require installation. You can use it as a portable software too.

## Infinite Dreamers FileRenamer

Infinite Dreamers FileRenamer is a free software to rename multiple files at once. To rename files you have to navigate to the directory whose files you want to rename. You can select all files at once from any directory using context menu. You can replace old name containing text string with new text string easily. You can add multiple replace strings simultaneously.

## Rename Us Pro

Rename Us Pro is a free file renaming utility for Windows. It lets you rename files in batch mode. You can set various options for renaming. You can add multiple rules for renaming like change case, enumeration, adding prefix or suffix to file names, using MP3 tags, file date etc. You can run it in the test mode to check the results before actually renaming.

## Renamer

Renamer is a free and simple file renaming software for Windows. It is very tiny in size but a useful file renaming tool. It has various functions to rename files. You can use its replace with space, search and replace, line by line replace, insert text at position, remove text by position and other various functions to rename files.

## UltimateReNamerJG

UltimateReNamerJG is a small, simple, and easy to use rename tool for Windows. It lets you batch rename multiple files at once. You can add multiple rules for renaming. With the help of it you can insert, delete, replace text strings from file names, can change extension, can change case, set incremental digits to specific position etc. It has a restore backup option if you accidently change file names.

## FileNameStringReplacer

FileNameStringReplacer is simple file renaming utility. It lets you find and replace specific text string from file names. It doesn’t require installation and can be used as a portable software. You can select the folder whose files have to be renamed from the select button. Set the search string to find in file names and type the replace with string to start renaming. It is easy to use software.

## RKrenamer

RKrenamer is a simple tool for renaming multiple files at once. You can rename large number of files in one go. You can insert text strings in file names, replace text, delete text, change case (upper/lower) or serialize the files. It also supports drag and drop feature. It has a simple and easy to use user interface.

## Personal Renamer

Personal Renamer is a free renaming tool for Windows. It lets you rename multiple files in a folder easily. It is a powerful batch file renamer and supports numbering or lettering files etc. You have to set the source and destination directory (both can be same) before you start renaming. You can set the various renaming rules in the advanced menu. You can undo the rename mistakes too.

## RenameApp

RenameApp is a free and easy to use file renaming software for Windows. It lets you easily rename files based upon the specified criteria and order. It supports drag and drop feature. You can preview rename results before you actually start the renaming process. You can add prefix or suffix to the file names, use specific names, can rename file extension etc.

## SolidRenamer

SolidRenamer is a free and easy to use file renaming software for Windows. It lets you rename files easily. It supports various rules for renaming files including prefixes, suffixes, inserting of text, clipping, replace text, change case, enumerations etc. You can set multiple rules for renaming in a sequence. It also has a preview facility before actually starting renaming process.

## File Batch Renamer

File Batch Renamer is a file renaming tool available free. You can rename multiple files or multiple types at once. You have to choose a common name, numbering style and separator to start renaming. You can select the output folder same or different from the source. It doesn’t have many options and is a simple file renaming tool.

## LuJoSoft Rename-All

LuJoSoft Rename-All is a simple and easy to use application to rename files. Some of its features includes add text to file names, remove text from file names, replace text, change case as uppercase or lowercase, capitalize each word etc. It has a preview option also. It shows the renamed files and original file names side by side.

## PSRenamer

PSRenamer is an open source program to rename files in batch mode. It lets you change any part of file name or its extension. You can add sequential numbers to file names. It has preview and undo functions also. As it is a JAR file and JAVA must be installed on the system to use it. It is small in size and can be used as a portable software.

## Daanav File Renamer

Daanav File Renamer is a free software to rename multiple files at once. It lets you rename various files with one click. You can find and replace text in the filenames, add incremental numbers, remove characters up to length you specify, change case (upper or lower) etc. to the file names. It is easy to use and has a user friendly interface.

Posted in Computer Research, Computer Softwares, Entertainment | Tagged: , , | Leave a Comment »

## OpenCV CUDA Sample Program

Posted by Hemprasad Y. Badgujar on July 17, 2015

### Design considerations

OpenCV GPU module is written using CUDA, therefore it benefits from the CUDA ecosystem. There is a large community, conferences, publications, many tools and libraries developed such as NVIDIA NPP, CUFFT, Thrust.

The GPU module is designed as host API extension. This design provides the user an explicit control on how data is moved between CPU and GPU memory. Although the user has to write some additional code to start using the GPU, this approach is both flexible and allows more efficient computations.

GPU modules includes class cv::gpu::GpuMat which is a primary container for data kept in GPU memory. It’s interface is very similar with cv::Mat, its CPU counterpart. All GPU functions receive GpuMat as input and output arguments. This allows to invoke several GPU algorithms without downloading data. GPU module API interface is also kept similar with CPU interface where possible. So developers who are familiar with Opencv on CPU could start using GPU straightaway.

### Short sample

In the sample below an image is loaded from png0file, next it is uploaded to GPU, thresholded, downloaded and displayed.

#include <iostream>
#include "opencv2/opencv.hpp"
#include "opencv2/gpu/gpu.hpp"

int main (int argc, char* argv[])
{
try
{
cv::gpu::GpuMat dst, src;

cv::gpu::threshold(src, dst, 128.0, 255.0, CV_THRESH_BINARY);

cv::Mat result_host = dst;
cv::imshow("Result", result_host);
cv::waitKey();
}
catch(const cv::Exception& ex)
{
std::cout << "Error: " << ex.what() << std::endl;
}
return 0;
}

Posted in Mixed | Tagged: , , , | Leave a Comment »

## OpenCV on CUDA Performance Comparison

Posted by Hemprasad Y. Badgujar on July 17, 2015

## Performance Table

For where i work, i had to test a lot of different GPU’s with come OpenCV GPU CUDA C++ functions, the GPU’s will end up in some rackservers. Anyhow, i tested some functions. You can press the figure to get a link to the performance table that is hosted with Google Docs.

### Models tested

 Computing Model Cuda V. Cores Frequency [MHz] Speedup (avg.) Intel i2600K ~ 4 3400 1 Intel Xeon E5620 ~ 4 2400 0.68x NVIDIA GTX 560 ASUS 2.1 336 810 22.4x NVIDIA GTX 570 EVGA 2.1 480 810 31.9x NVIDIA GTX 670 EVGA 3.0 1344 950 34.96x NVIDIA GTX 680 EVGA 3.0 1536 1058 34.90x

*I used Ubuntu 12.04, CUDA 4.2, Opencv 2.4 C++ (latest svn snapshot), NVIDIA 295.51 driver.

### Functions tested

matchTemplate, minMaxLoc, remap, dft, cornerHarris, integral, norm, meanShift, BruteForceMatcher, magnitude, add, log, mulSpectrums, resize, cvtColor, erode, threshold, pow, projectPoints, solvePnPRansac, GaussianBlur, filter2D, pyrDown, pyrUp, equializeHist, reduce.

## Test Setup

### Conclusion

In terms of value for money, the GTX 670 (€400) with 2Gb of RAM is very nice. There is absolutely no reason to buy the GTX 680 since it costs € 100 more. Then again, the GTX 570 costs €300, which is nice, but only has 1,25Gb RAM, which can be dangerous when working with large images (nasty errors).
It is clear that GPU computation is BLOODY fast. But i HAVE to note, that only a SINGLE core of the CPU’s were used for the normal CPU functions. These algo’s have not really been optimized for multithreaded if I’m not mistaken. On the other hand, speed increases of >20x is too much for any intel CPU to catch up with. GPU Computing is a must if fast image processing is important.

## GPU + GPU = Multi GPU

Multi GPU? Yes! Using 2xGTX670’s, you can use 2688 CORES. That means that if you don’t keep your GPU’s on a leash it might become self aware. You have been warned.
Oh yes, MULTI GPU! OpenCV only natively supports 1 GPU per function, but ofcourse you can use more if you want. OpenCV themselves suggest Intel’s TBB (thread building blocks) for some reason. OpenCV once started with OpenMP (open source parallel/multithread processing), but do not support that any more. Luckily, If you know your way around OpenMP, it is quite easy to implement.
You can use more GPU’s in OpenCV, there are some functions wich you can use with it. I tend to use OpenMP, make a simple parallel loop with some conditions, and within the thread just use the “gpu::setDevice” C++ function to set which device to use within that thread. For example, when you have two GPU’s, it is a good idea to let OpenMP set “num_threads(2)”, so each GPU has got its own thread, and with the setDevice function, you just use ‘gpu::setDevice(omp_get_thread)’ for example. I got a speed increase of 40~80% using 2 GPU’s, see the nice setup i had in my desktop where i tried it. It will eventually end up in the rackserver, purely for GPU computation, for which they are ideal.

### Code for Multi-GPU in OpenCV with OpenMP

1. bool useMGPU=true;
2. bool useMP=true;
3. int numGPUs=gpu::getCudaEnabledDeviceCount();
4. omp_set_nested(1); //Turn on nested MP (to use parallel loops in your loop)
5. #pragma omp parallel if (useMP) num_threads(2)
6. {
7. #pragma omp for
8. for (int i=0;i<10;i++){
9.    //If Multiple GPU support is on, assign based on threadnr
10.    int threadID = omp_get_thread_num();
11.    if (useMGPU && numGPUs>1){
12.        cout << "Setting GPU#" << threadID << " for i#" << i << endl;
13.        gpu::setDevice(threadID);
14.    }
15.    //Your GPU code here. The device has been set
16.

17.    //..
18.

19.    //Test to see if the GPU has been properly set throughout the loop (device should be == threadID)
20.    if (useMGPU){
21.        cout << " Had set GPU#" << gpu::getDevice() << " with tID#" << threadID << " (i#" << i << ")" << endl;
22.    }
23. }
24. }

## Open road databases for lane tracking and vehicle detection

Posted by Hemprasad Y. Badgujar on May 16, 2015

“free” for a researcher willing to test his own algorithms of lane tracking or vehicle detection.

Although it is quite easy to find webpages with huge databases with images of vehicles, it is not so easy to find sites where there are videos of the road ahead captured with a camera installed in a vehicle.

We finally found some, which include in some cases the original videos and the videos with the overimposed detection of vehicles, pedestrians and things like that.

Here you are the list with the links and a short description of the owner:

Thanks to the researchers that share their databases! You support the whole research community with your effort!!

ThuyDX

Just another WordPress.com site

josephdung

thoughts...

Algunos Intereses de Abraham Zamudio Chauca

Matematica, Linux , Programacion Serial , Programacion Paralela (CPU - GPU) , Cluster de Computadores , Software Cientifico

Tech_Raj

A great WordPress.com site

Travel tips

Travel tips

Experience the real life.....!!!

Shurwaat achi honi chahiye ...

Ronzii's Blog

Just your average geek's blog

Karan Jitendra Thakkar

Everything I think. Everything I do. Right here.

VentureBeat

News About Tech, Money and Innovation

Chetan Solanki

Helpful to u, if u need it.....

Explorer of Research #HEMBAD

managedCUDA

Explorer of Research #HEMBAD

siddheshsathe

A great WordPress.com site

Ari's

This is My Space so Dont Mess With IT !!