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
f8d0c556
Commit
f8d0c556
authored
Mar 27, 2014
by
Ravi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
camera with grayscale working
parent
1ae438e8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
19 deletions
+12
-19
Makefile
miklos/project_primal_dual/Makefile
+3
-1
main.cu
miklos/project_primal_dual/main.cu
+9
-18
No files found.
miklos/project_primal_dual/Makefile
View file @
f8d0c556
all
:
main
main
:
main.cu aux.cu aux.h Makefile
nvcc
-o
main main.cu aux.cu
--ptxas-options
=
-v
--use_fast_math
--compiler-options
-Wall
-lopencv_highgui
-lopencv_core
nvcc
-o
main main.cu aux.cu
--ptxas-options
=
-v
--use_fast_math
--compiler-options
-Wall
-lopencv_highgui
-lopencv_core
-lopencv_imgproc
miklos/project_primal_dual/main.cu
View file @
f8d0c556
...
...
@@ -28,7 +28,7 @@
using namespace std;
// uncomment to use the camera
//
#define CAMERA
#define CAMERA
template<typename T>
__device__ __host__ T min(T a, T b)
...
...
@@ -186,6 +186,7 @@ int main(int argc, char **argv)
// read in first frame to get the dimensions
cv::Mat mIn;
camera >> mIn;
cvtColor(mIn, mIn, CV_BGR2GRAY);
#else
...
...
@@ -207,15 +208,10 @@ int main(int argc, char **argv)
cout << "image: " << w << " x " << h << endl;
// Set the output image format
cv::Mat mOut(h,w,mIn.type()); // mOut will have the same number of channels as the input image, nc layers
// ### Define your own output images here as needed
// Allocate arrays
// input/output image width: w
// input/output image height: h
...
...
@@ -229,9 +225,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:
...
...
@@ -242,6 +235,7 @@ int main(int argc, char **argv)
// Get camera image
camera >> mIn;
// convert to float representation (opencv loads image values as single bytes by default)
cvtColor(mIn, mIn, CV_BGR2GRAY);
mIn.convertTo(mIn,CV_32F);
// convert range of each channel to [0,1] (opencv default is [0,255])
mIn /= 255.f;
...
...
@@ -251,12 +245,15 @@ int main(int argc, char **argv)
// 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);
dim3 block(32, 16);
dim3 grid = make_grid(dim3(w, h, 1), block);
Timer timer; timer.start();
for ( int jk = 0; jk < repeats; jk++ ) {
float *d_T, *d_U, *d_F, *d_Xi, *d_Xj;
cudaMalloc(&d_T, imageBytes);
cudaMalloc(&d_U, imageBytes);
...
...
@@ -282,13 +279,10 @@ int main(int argc, char **argv)
cudaFree(d_F);
cudaFree(d_Xi);
cudaFree(d_Xj);
timer.end(); float t = timer.get(); // elapsed time in seconds
cout << "time: " << t*1000 << " ms" << endl;
}
timer.end(); float t = timer.get(); // elapsed time in seconds
cout << "time: " << t*1000/repeats << " ms" << endl;
// show input image
showImage("Input", mIn, 100, 100); // show at position (x_from_left=100,y_from_above=100)
...
...
@@ -307,9 +301,6 @@ int main(int argc, char **argv)
cv::waitKey(0);
#endif
// save input and result
cv::imwrite("image_input.png",mIn*255.f); // "imwrite" assumes channel range [0,255]
cv::imwrite("image_result.png",mOut*255.f);
...
...
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