Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
C
cuda_lab
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Gaurav Kukreja
cuda_lab
Commits
5aeb8c49
Commit
5aeb8c49
authored
Mar 05, 2014
by
Gaurav Kukreja
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Convolution: fixed error when using camera
Signed-off-by:
Gaurav Kukreja
<
gaurav@gauravk.in
>
parent
bf02d566
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
44 deletions
+43
-44
main.cu
gaurav/1_Assign/ex6/main.cu
+43
-44
No files found.
gaurav/1_Assign/ex6/main.cu
View file @
5aeb8c49
...
...
@@ -29,9 +29,9 @@
using namespace std;
// uncomment to use the camera
//
#define CAMERA
#define CAMERA
//
#define USING_GPU
#define USING_GPU
template<typename T>
__device__ T gpu_min(T a, T b)
...
...
@@ -190,30 +190,6 @@ int main(int argc, char **argv)
// allocate raw output array (the computation result will be stored in this array, then later converted to mOut for displaying)
float *imgOut = new float[(size_t)w*h*mOut.channels()];
// For camera mode: Make a loop to read in camera frames
#ifdef CAMERA
// Read a camera image frame every 30 milliseconds:
// cv::waitKey(30) waits 30 milliseconds for a keyboard input,
// returns a value <0 if no key is pressed during this time, returns immediately with a value >=0 if a key is pressed
while (cv::waitKey(30) < 0)
{
// Get camera image
camera >> mIn;
// convert to float representation (opencv loads image values as single bytes by default)
mIn.convertTo(mIn,CV_32F);
// convert range of each channel to [0,1] (opencv default is [0,255])
mIn /= 255.f;
#endif
// Init raw input image array
// opencv images are interleaved: rgb rgb rgb... (actually bgr bgr bgr...)
// But for CUDA it's better to work with layered images: rrr... ggg... bbb...
// So we will convert as necessary, using interleaved "cv::Mat" for loading/saving/displaying, and layered "float*" for CUDA computations
convert_mat_to_layered (imgIn, mIn);
int rad = ceil(3 * sigma); // kernel radius
int kw = 2 * rad; // kernel width
float c = 1. / (2. * 3.142857 * sigma * sigma); // constant
...
...
@@ -226,13 +202,13 @@ int main(int argc, char **argv)
float b;
for (int iy = 0; iy < kw; iy++)
{
a = iy - rad;
for (int ix = 0; ix < kw; ix++)
{
b = ix - rad;
kernel[ix + (iy * kw)] = c * exp(-(a*a + b*b) / (2 * sigma*sigma));
}
}
a = iy - rad;
for (int ix = 0; ix < kw; ix++)
{
b = ix - rad;
kernel[ix + (iy * kw)] = c * exp(-(a*a + b*b) / (2 * sigma*sigma));
}
}
// Normalization of Kernel
float sum = 0.;
...
...
@@ -240,19 +216,19 @@ int main(int argc, char **argv)
for (int iy = 0; iy < kw; iy++)
{
for (int ix = 0; ix < kw; ix++)
{
kmax = max(kmax, kernel[ix + (iy * kw)]);
sum += kernel[ix + (iy * kw)];
}
{
kmax = max(kmax, kernel[ix + (iy * kw)]);
sum += kernel[ix + (iy * kw)];
}
}
for (int iy = 0; iy < kw; iy++)
{
for (int ix = 0; ix < kw; ix++)
{
kernelOut[ix + (iy * kw)] = kernel[ix + (iy * kw)] / kmax;
kernel[ix + (iy * kw)] = kernel[ix + (iy * kw)] / sum;
}
{
for (int ix = 0; ix < kw; ix++)
{
kernelOut[ix + (iy * kw)] = kernel[ix + (iy * kw)] / kmax;
kernel[ix + (iy * kw)] = kernel[ix + (iy * kw)] / sum;
}
}
// Display Kernel
...
...
@@ -260,6 +236,28 @@ int main(int argc, char **argv)
convert_layered_to_mat(cvKernelOut, kernelOut);
showImage("Kernel", cvKernelOut, 100, 10);
// For camera mode: Make a loop to read in camera frames
#ifdef CAMERA
// Read a camera image frame every 30 milliseconds:
// cv::waitKey(30) waits 30 milliseconds for a keyboard input,
// returns a value <0 if no key is pressed during this time, returns immediately with a value >=0 if a key is pressed
while (cv::waitKey(30) < 0)
{
// Get camera image
camera >> mIn;
// convert to float representation (opencv loads image values as single bytes by default)
mIn.convertTo(mIn,CV_32F);
// convert range of each channel to [0,1] (opencv default is [0,255])
mIn /= 255.f;
#endif
// Init raw input image array
// opencv images are interleaved: rgb rgb rgb... (actually bgr bgr bgr...)
// But for CUDA it's better to work with layered images: rrr... ggg... bbb...
// So we will convert as necessary, using interleaved "cv::Mat" for loading/saving/displaying, and layered "float*" for CUDA computations
convert_mat_to_layered (imgIn, mIn);
Timer timer;
float t;
// ###
...
...
@@ -320,7 +318,7 @@ int main(int argc, char **argv)
{
for(int iy = 0; iy < h; iy++)
{
for(int iz = 0; iz <
h
; iz++)
for(int iz = 0; iz <
nc
; iz++)
{
int idx = ix + (iy * w) + (iz * w * h);
imgOut[idx] = 0; // initialize
...
...
@@ -377,6 +375,7 @@ int main(int argc, char **argv)
delete[] imgIn;
delete[] imgOut;
delete[] kernel;
delete[] kernelOut;
// close all opencv windows
cvDestroyAllWindows();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment