unsigned long AAtime = 0, BBtime = 0; cuda::GpuMat gpuImg, gpuImg_out; Mat img, img_out, img_out2; img = imread("2mb.jpg"); gpuImg.upload(img); AAtime = getTickCount(); cuda::bitwise_not(gpuImg, gpuImg_out); Ptr< cv::cuda::filter > filter = cuda::createSobelFilter(img.type(), img.type(), 1, 0); filter->apply(gpuImg_out, gpuImg_out); BBtime = getTickCount(); gpuImg_out.download(img_out); printf("gpu : %.2lf second \n", (BBtime - AAtime) / getTickFrequency()); AAtime = getTickCount(); bitwise_not(img, img_out2); Sobel(img_out2, img_out2, img_out2.depth(), 1, 0); BBtime = getTickCount(); printf("cpu : %.2lf second \n", (BBtime - AAtime) / getTickFrequency()); imshow("cpu_img", img_out); imshow("cpu_img", img_out2); waitKey(0);
12/16/2016
Gpu Mat, Cpu Mat example 2
Gpu Mat, Cpu Mat example code 1
...
#include "opencv2/opencv.hpp" #include "opencv2/highgui.hpp" #include "opencv2/cudaarithm.hpp" #include <iostream> #ifdef _DEBUG #pragma comment(lib, "opencv_core331d.lib") #pragma comment(lib, "opencv_highgui331d.lib") #pragma comment(lib, "opencv_imgcodecs331d.lib") #pragma comment(lib, "opencv_objdetect331d.lib") #pragma comment(lib, "opencv_imgproc331d.lib") #pragma comment(lib, "opencv_videoio331d.lib") #pragma comment(lib, "opencv_cudaarithm331d.lib") #else #pragma comment(lib, "opencv_core331.lib") #pragma comment(lib, "opencv_highgui331.lib") #pragma comment(lib, "opencv_imgcodecs331.lib") #pragma comment(lib, "opencv_objdetect331.lib") #pragma comment(lib, "opencv_imgproc331.lib") #pragma comment(lib, "opencv_videoio331.lib") #pragma comment(lib, "opencv_cudaarithm331d.lib") #endif using namespace std; using namespace cv; int main() { cuda::GpuMat gpuImg; Mat img = imread("ss.jpg"); gpuImg.upload(img); //upload vector< cuda::GpuMat> rgbGpuMat(3); cuda::split(gpuImg, rgbGpuMat); //cuda processing Mat r, g, b; rgbGpuMat[0].download(b); //download rgbGpuMat[1].download(g); rgbGpuMat[2].download(r); namedWindow("r", 0); //make window imshow("r", r); //show namedWindow("g", 0); //make window imshow("g", g); //show namedWindow("b", 0); //make window imshow("b", b); //show waitKey(0); return 0; }...
SVD (singular value decomposition) example in opencv
//Singular value decomposition : Mat w, u, v; SVDecomp(data, w, u, v); // A = U W V^T //The flags cause U and V to be returned transposed(does not work well without the transpose flags). cout << u << endl; cout << w << endl; cout << v << endl;
Eigen analysis(of a symmetric matrix) in opencv exmaple code
//Eigen analysis(of a symmetric matrix) : float f11[] = { 1, 0.446, -0.56, 0.446, 1, -0.239, -0.56, 0.239, 1 }; Mat data(3, 3, CV_32F, f11); cout << "input data" << endl; cout << data << endl; Mat value, vector; eigen(data, value, vector); cout << "Eigenvalues" << endl << value << endl; cout << "Eigenvectors" << endl << vector << endl;proof
cout << vector << endl; cout << endl << "AV" << endl; cout << data * vector << endl; cout << "vV" << endl; Mat ValueEye = Mat::eye(3, 3, CV_32F); ValueEye.at< float>(0, 0) = value.at< float>(0, 0); ValueEye.at< float>(1, 1) = value.at< float>(1, 0); ValueEye.at< float>(2, 2) = value.at< float>(2, 0); cout << vector*ValueEye << endl;
Inhomogeneous linear system solver in opencv (Example code)
double dm2[3][3] = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } }; Mat A(3, 3, CV_64FC1, dm2); Mat x(3, 1, CV_64FC1); double vvb[] = { 14, 32, 52 }; Mat b(3, 1, CV_64FC1, vvb); cv::solve(A, b, x, DECOMP_SVD); //// solve (Ax=b) for x cout << x << endl;
12/14/2016
ctime_s and ctime example
#include < time.h > #include < stdio.h > int main(void) { time_t result = time(NULL); //printf("%ld \n", result); //printf("%s \n", ctime(&result)); char str[26]; ctime_s(str,sizeof str,&result); printf("%s \n", str); }
-> result
Thu Dec 15 02:29:54 2016
Subscribe to:
Posts (Atom)
-
make well divided linear coordinate And make pair coordinate Please see code for detail explanation. import numpy as np import cv2 ...
-
As you can see in the following video, I created a class that stitching n cameras in real time. https://www.youtube.com/user/feelmare/sear...
-
In past, I wrote an articel about YUV 444, 422, 411 introduction and yuv <-> rgb converting example code. refer to this page -> ht...
-
Image size of origin is 320*240. Processing time is 30.96 second took. The result of stitching The resul...
-
* Introduction - The solution shows panorama image from multi images. The panorama images is processing by real-time stitching algorithm...
-
Proceed with the project to update the 2012 version, or that you must reinstall Visual Studio 2010. If you are using Visual Studio 2...
-
1. Map : Tasks read from and write to specific data elements. 2. Gather : each calculation gathers input data elements together from di...
-
fig 1. Left: set 4 points (Left Top, Right Top, Right Bottom, Left Bottom), right:warped image to (0,0) (300,0), (300,300), (0,300) Fi...
-
opencv lecture 4-1 example code < gist start > < gist end >
-
//Singular value decomposition : Mat w, u, v; SVDecomp(data, w, u, v); // A = U W V^T //The flags cause U and V to be returned transpose...
