Just change mode
and run!
'./' means sh command
# chmod a+x install_test.run
# ./install_test.run
Linux is not easy to me.....
#include < iostream> #include < vector> #include < stdio.h> #include < opencv2\opencv.hpp> #include < opencv2\legacy\legacy.hpp> #ifdef _DEBUG #pragma comment(lib, "opencv_core249d.lib") #pragma comment(lib, "opencv_imgproc249d.lib") //MAT processing #pragma comment(lib, "opencv_objdetect249d.lib") //HOGDescriptor //#pragma comment(lib, "opencv_gpu249d.lib") //#pragma comment(lib, "opencv_features2d249d.lib") #pragma comment(lib, "opencv_highgui249d.lib") #pragma comment(lib, "opencv_ml249d.lib") //#pragma comment(lib, "opencv_stitching249d.lib"); //#pragma comment(lib, "opencv_nonfree249d.lib"); #pragma comment(lib, "opencv_video249d.lib") #pragma comment(lib, "opencv_legacy249d.lib") #else #pragma comment(lib, "opencv_core249.lib") #pragma comment(lib, "opencv_imgproc249.lib") #pragma comment(lib, "opencv_objdetect249.lib") //#pragma comment(lib, "opencv_gpu249.lib") //#pragma comment(lib, "opencv_features2d249.lib") #pragma comment(lib, "opencv_highgui249.lib") #pragma comment(lib, "opencv_ml249.lib") //#pragma comment(lib, "opencv_stitching249.lib"); //#pragma comment(lib, "opencv_nonfree249.lib"); #pragma comment(lib, "opencv_video249d.lib") #endif using namespace cv; using namespace std; // (1) functions for calculating the likelihood float calc_likelihood (IplImage * img, int x, int y) { float b, g, r; float dist = 0.0, sigma = 50.0; b = img->imageData[img->widthStep * y + x * 3]; //B g = img->imageData[img->widthStep * y + x * 3 + 1]; //G r = img->imageData[img->widthStep * y + x * 3 + 2]; //R dist = sqrt (b * b + g * g + (255.0 - r) * (255.0 - r)); return 1.0 / (sqrt (2.0 * CV_PI) * sigma) * expf (-dist * dist / (2.0 * sigma * sigma)); } void ProccTimePrint( unsigned long Atime , string msg) { unsigned long Btime=0; float sec, fps; Btime = getTickCount(); sec = (Btime - Atime)/getTickFrequency(); fps = 1/sec; printf("%s %.4lf(sec) / %.4lf(fps) \n", msg.c_str(), sec, fps ); } int main () { float TakeTime; unsigned long Atime, Btime; int i, c; double w = 0.0, h = 0.0; CvCapture *capture = 0; IplImage *frame = 0; int n_stat = 4; int n_particle = 1000; vector< float > vx(n_particle); vector< float > vy(n_particle); CvConDensation *cond = 0; CvMat *lowerBound = 0; CvMat *upperBound = 0; int xx, yy; // (2)you want to create a capture structure with respect to the camera with the specified number by the command argument capture = cvCreateCameraCapture(0); // (3)The one frame captured, and obtains the capture size. frame = cvQueryFrame (capture); w = frame->width; h = frame->height; cvNamedWindow ("Condensation", CV_WINDOW_AUTOSIZE); // (4)Condensation create a structure. cond = cvCreateConDensation (n_stat, 0, n_particle); // (5) it will specify the minimum and maximum values of the state vector can be taken for each dimension. lowerBound = cvCreateMat (4, 1, CV_32FC1); upperBound = cvCreateMat (4, 1, CV_32FC1); cvmSet (lowerBound, 0, 0, 0.0); cvmSet (lowerBound, 1, 0, 0.0); cvmSet (lowerBound, 2, 0, -10); //-10.0); cvmSet (lowerBound, 3, 0, -10); //-10.0); cvmSet (upperBound, 0, 0, w); cvmSet (upperBound, 1, 0, h); cvmSet (upperBound, 2, 0, 10); //10.0); cvmSet (upperBound, 3, 0, 10); //10.0); // (6)Condensation Initialize the structure cvConDensInitSampleSet (cond, lowerBound, upperBound); // (7)ConDensation Specify the dynamics of the state vector in the algorithm cond->DynamMatr[0] = 1.0; cond->DynamMatr[1] = 0.0; cond->DynamMatr[2] = 1.0; cond->DynamMatr[3] = 0.0; cond->DynamMatr[4] = 0.0; cond->DynamMatr[5] = 1.0; cond->DynamMatr[6] = 0.0; cond->DynamMatr[7] = 1.0; cond->DynamMatr[8] = 0.0; cond->DynamMatr[9] = 0.0; cond->DynamMatr[10] = 1.0; cond->DynamMatr[11] = 0.0; cond->DynamMatr[12] = 0.0; cond->DynamMatr[13] = 0.0; cond->DynamMatr[14] = 0.0; cond->DynamMatr[15] = 1.0; // (8)re-set the noise parameters. while (1) { frame = cvQueryFrame (capture); Atime = getTickCount(); //μμ μκ° float a=0,b=0,c=0,d=0,e=0; // (9) It calculates the likelihood for each particle. for (i = 0; i < n_particle; i++) { xx = (int) (cond->flSamples[i][0]); yy = (int) (cond->flSamples[i][1]); vx[i] = cond->flSamples[i][0]; vy[i] = cond->flSamples[i][1]; if (xx < 0 || xx >= w || yy < 0 || yy >= h) { cond->flConfidence[i] = 0.0; } else { cond->flConfidence[i] = calc_likelihood (frame, xx, yy); cvCircle (frame, cvPoint (xx, yy), 1, CV_RGB (0, 0, 255), -1); } } // (10) estimate the state of the next model cvConDensUpdateByTime (cond); printf("crrection \n"); ProccTimePrint( Atime , "time :"); //μ²λ¦¬μκ° μΆλ ₯ cv::Point statePt(cond->State[0], cond->State[1]); cvCircle (frame, statePt, 5, CV_RGB (255, 255, 255), 5); printf("-----------\n"); cvShowImage ("Condensation", frame); if (cvWaitKey (10) > 10 ) break; } cvDestroyWindow ("Condensation"); cvReleaseCapture (&capture); cvReleaseConDensation (&cond); cvReleaseMat (&lowerBound); cvReleaseMat (&upperBound); return 0; }
#include < iostream> #include "opencv2\objdetect\objdetect.hpp" #include "opencv2\highgui\highgui.hpp" #include "opencv2\imgproc\imgproc.hpp" #include "opencv2\cudaobjdetect.hpp" #include "opencv2\cudaimgproc.hpp" #include "opencv2\cudawarping.hpp" #ifdef _DEBUG #pragma comment(lib, "opencv_core300d.lib") #pragma comment(lib, "opencv_highgui300d.lib") #pragma comment(lib, "opencv_imgcodecs300d.lib") #pragma comment(lib, "opencv_objdetect300d.lib") #pragma comment(lib, "opencv_imgproc300d.lib") #pragma comment(lib, "opencv_videoio300d.lib") #pragma comment(lib, "opencv_cudaobjdetect300d.lib") #pragma comment(lib, "opencv_cudawarping300d.lib") #pragma comment(lib, "opencv_cudaimgproc300d.lib") #else #pragma comment(lib, "opencv_core300.lib") #pragma comment(lib, "opencv_highgui300.lib") #pragma comment(lib, "opencv_imgcodecs300.lib") #pragma comment(lib, "opencv_objdetect300.lib") #pragma comment(lib, "opencv_imgproc300.lib") #pragma comment(lib, "opencv_videoio300.lib") #pragma comment(lib, "opencv_cudaobjdetect300.lib") #pragma comment(lib, "opencv_cudawarping300.lib") #pragma comment(lib, "opencv_cudaimgproc300.lib") #endif using namespace std; using namespace cv; void main() { cv::Ptr< cv::cuda::HOG> d_hog = cv::cuda::HOG::create(Size(48, 96)); //Size(64, 128));// d_hog->setSVMDetector(d_hog->getDefaultPeopleDetector()); //video loading Mat img; VideoCapture cap("M:\\____videoSample____\\tracking\\TownCentreXVID.avi"); //loading test cap >> img; if (img.empty()) return; //window namedWindow("pedestrian", 0); //processing time check unsigned long AAtime = 0, BBtime = 0; //resize double scale = float(800) / img.cols; cuda::GpuMat GpuImg, rGpuImg; GpuImg.upload(img); cuda::resize(GpuImg, rGpuImg, Size(GpuImg.cols * scale, GpuImg.rows * scale)); Mat rInimg; rGpuImg.download(rInimg); while (1) { //time check AAtime = getTickCount(); //loading cap >> img; if (img.empty()) break; //resize GpuImg.upload(img); cuda::resize(GpuImg, rGpuImg, Size(GpuImg.cols * scale, GpuImg.rows * scale)); rGpuImg.download(rInimg); cuda::cvtColor(rGpuImg, rGpuImg, CV_BGR2GRAY); vector< Point> found_locations; d_hog->detect(rGpuImg, found_locations); std::vector< cv::Rect> found_locations_rect; d_hog->detectMultiScale(rGpuImg, found_locations_rect); for (int i = 0; i < found_locations_rect.size(); ++i) { cv::rectangle(rInimg, found_locations_rect[i], CvScalar(0, 0, 255), 1); } imshow("pedestrian", rInimg); waitKey(10); //time check BBtime = getTickCount(); double s_time = (BBtime - AAtime) / getTickFrequency(); double fps_time = 1/s_time; printf("%.2lf sec / %.2lf fps \n", s_time, fps_time); } }
#ifdef DEBUG wchar_t str[100]; swprintf(str,L"if %d %lf\n", valueInt, valueDouble); OutputDebugString( str ); #endif
printf %Get R,T from 2 groups of 3d points %The first group is created by random selection A3pt = rand(3, 10); figure(10); plot3(A3pt(1,:),A3pt(2,:),A3pt(3,:),'r.');%, axis equal %The second group is made by random R,T from first group v1=0.6*(2*rand-1); v2=0.6*(2*rand-1); v3=0.6*(2*rand-1); R1=[1 0 0;0 cos(v1) -sin(v1);0 sin(v1) cos(v1)]; R2=[cos(v2) 0 sin(v2);0 1 0;-sin(v2) 0 cos(v2)]; R3=[cos(v3) -sin(v3) 0;sin(v3) cos(v3) 0;0 0 1]; R=R3*R2*R1; T = rand(3,1); B3pt = R*A3pt; %Rotation for i=1:3 %dimension B3pt(i,:)=B3pt(i,:)+T(i); % translation end %show 2 group figure(1); plot3(A3pt(1,:),A3pt(2,:),A3pt(3,:),'r.',B3pt(1,:),B3pt(2,:),B3pt(3,:),'bo');%, axis equal %% get R,T MeanA = mean(A3pt, 2); MeanB = mean(B3pt, 2); HH=zeros(3,3); n = length(A3pt); for i=1:n tA = A3pt(:,i) - MeanA; tB = B3pt(:,i) - MeanB; hh = tB * tA'; HH = HH + hh; end [U,~,V]=svd(HH); Ri=V*U'; %get R Ti=MeanA-Ri*MeanB; %Get T %% confirm B3pt_=Ri*B3pt; % Rotation μν€κΈ° Apply transformation for i=1:3 %dimension B3pt_(i,:)=B3pt_(i,:)+Ti(i); % translation μν€κΈ° end %show 2 group figure(2); plot3(A3pt(1,:),A3pt(2,:),A3pt(3,:),'r.',B3pt_(1,:),B3pt_(2,:),B3pt_(3,:),'bo');%, axis equal...
int increase = 0; char str[100]; _itoa_s(time(0),str,10); //10 means decimal so 8:octal, 16Lhex, 2:binary sprintf_s(str, "%s_%d", str, increase); printf("%s \n", str );...
Rect A(100, 100, 100, 100); //x, y, width, hegiht Rect B(80, 80, 100, 100); //x, y, width, hegiht printf("intersection area= %d\n", (A&B).area()); printf("union area = %d\n", (A|B).area()); printf("instersection ratio %lf \n", (A&B).area() / float( (A | B).area() ));..
#include < iostream> #include "opencv2\objdetect\objdetect.hpp" #include "opencv2\highgui\highgui.hpp" #include "opencv2\imgproc\imgproc.hpp" #include "opencv2\cudaobjdetect.hpp" #include "opencv2\cudaimgproc.hpp" #include "opencv2\cudawarping.hpp" #include < opencv2\bgsegm.hpp> #include < opencv2\cudabgsegm.hpp> #include < opencv2\cudaoptflow.hpp> #ifdef _DEBUG #pragma comment(lib, "opencv_core300d.lib") #pragma comment(lib, "opencv_highgui300d.lib") #pragma comment(lib, "opencv_imgcodecs300d.lib") #pragma comment(lib, "opencv_objdetect300d.lib") #pragma comment(lib, "opencv_imgproc300d.lib") #pragma comment(lib, "opencv_videoio300d.lib") #pragma comment(lib, "opencv_cudaobjdetect300d.lib") #pragma comment(lib, "opencv_cudawarping300d.lib") #pragma comment(lib, "opencv_cudaimgproc300d.lib") #pragma comment(lib, "opencv_cudabgsegm300d.lib") #pragma comment(lib, "opencv_cudaoptflow300d.lib") #else #pragma comment(lib, "opencv_core300.lib") #pragma comment(lib, "opencv_highgui300.lib") #pragma comment(lib, "opencv_imgcodecs300.lib") #pragma comment(lib, "opencv_objdetect300.lib") #pragma comment(lib, "opencv_imgproc300.lib") #pragma comment(lib, "opencv_videoio300.lib") #pragma comment(lib, "opencv_cudaobjdetect300.lib") #pragma comment(lib, "opencv_cudawarping300.lib") #pragma comment(lib, "opencv_cudaimgproc300.lib") #pragma comment(lib, "opencv_cudabgsegm300.lib") #pragma comment(lib, "opencv_cudaoptflow300.lib") #endif using namespace cv; using namespace std; static void download(const cuda::GpuMat& d_mat, vector< Point2f>& vec); static void download(const cuda::GpuMat& d_mat, vector< uchar>& vec); static void drawArrows(Mat& frame, const vector< Point2f>& prevPts, const vector< Point2f>& nextPts, const vector< uchar>& status, Scalar line_color = Scalar(0, 0, 255)); void main() { //variable cuda::GpuMat GpuImg, rGpuImg_Bgray; cuda::GpuMat oldGpuImg_Agray; //video Mat img, dImg_rg, dimg; VideoCapture cap("M:\\____videoSample____\\tracking\\TownCentreXVID.avi"); cap >> img; if (img.empty()) return; //scale double scale = 800. / img.cols; //first gpumat GpuImg.upload(img); cuda::resize(GpuImg, oldGpuImg_Agray, Size(GpuImg.cols * scale, GpuImg.rows * scale)); cuda::cvtColor(oldGpuImg_Agray, oldGpuImg_Agray, CV_BGR2GRAY); cuda::GpuMat d_prevPts; cuda::GpuMat d_nextPts; cuda::GpuMat d_status; Ptr< cuda::CornersDetector> detector = cuda::createGoodFeaturesToTrackDetector(oldGpuImg_Agray.type(), 4000, 0.01, 0); //opticla flow Ptr< cuda::SparsePyrLKOpticalFlow> d_pyrLK = cuda::SparsePyrLKOpticalFlow::create(Size(21, 21), 3, 30); unsigned long Atime, Btime; float TakeTime; while (1) { Atime = getTickCount(); cap >> img; if (img.empty()) break; //get image GpuImg.upload(img); cuda::resize(GpuImg, rGpuImg_Bgray, Size(GpuImg.cols * scale, GpuImg.rows * scale)); rGpuImg_Bgray.download(dimg); cuda::cvtColor(rGpuImg_Bgray, rGpuImg_Bgray, CV_BGR2GRAY); rGpuImg_Bgray.download(dImg_rg); //A,B image //oldGpuImg_Agray; //rGpuImg_Bgray; //feature detector->detect(oldGpuImg_Agray, d_prevPts); d_pyrLK->calc(oldGpuImg_Agray, rGpuImg_Bgray, d_prevPts, d_nextPts, d_status); //old oldGpuImg_Agray = rGpuImg_Bgray; // Draw arrows vector< Point2f> prevPts(d_prevPts.cols); download(d_prevPts, prevPts); vector< Point2f> nextPts(d_nextPts.cols); download(d_nextPts, nextPts); vector< uchar> status(d_status.cols); download(d_status, status); drawArrows(dimg, prevPts, nextPts, status, Scalar(255, 0, 0)); //show imshow("PyrLK [Sparse]", dimg); imshow("origin", dImg_rg); if (waitKey(10)>0) break; Btime = getTickCount(); TakeTime = (Btime - Atime) / getTickFrequency(); printf("%lf sec / %lf fps \n", TakeTime, 1 / TakeTime); } } static void download(const cuda::GpuMat& d_mat, vector< uchar>& vec) { vec.resize(d_mat.cols); Mat mat(1, d_mat.cols, CV_8UC1, (void*)&vec[0]); d_mat.download(mat); } static void download(const cuda::GpuMat& d_mat, vector< Point2f>& vec) { vec.resize(d_mat.cols); Mat mat(1, d_mat.cols, CV_32FC2, (void*)&vec[0]); d_mat.download(mat); } static void drawArrows(Mat& frame, const vector< Point2f>& prevPts, const vector< Point2f>& nextPts, const vector< uchar>& status, Scalar line_color) { for (size_t i = 0; i < prevPts.size(); ++i) { if (status[i]) { int line_thickness = 1; Point p = prevPts[i]; Point q = nextPts[i]; double angle = atan2((double)p.y - q.y, (double)p.x - q.x); double hypotenuse = sqrt((double)(p.y - q.y)*(p.y - q.y) + (double)(p.x - q.x)*(p.x - q.x)); if (hypotenuse < 1.0) continue; // Here we lengthen the arrow by a factor of three. q.x = (int)(p.x - 3 * hypotenuse * cos(angle)); q.y = (int)(p.y - 3 * hypotenuse * sin(angle)); // Now we draw the main line of the arrow. line(frame, p, q, line_color, line_thickness); // Now draw the tips of the arrow. I do some scaling so that the // tips look proportional to the main line of the arrow. p.x = (int)(q.x + 9 * cos(angle + CV_PI / 4)); p.y = (int)(q.y + 9 * sin(angle + CV_PI / 4)); line(frame, p, q, line_color, line_thickness); p.x = (int)(q.x + 9 * cos(angle - CV_PI / 4)); p.y = (int)(q.y + 9 * sin(angle - CV_PI / 4)); line(frame, p, q, line_color, line_thickness); } } }...
#include < iostream> #include < stdio.h> #include < vector> #include < time.h> #include < opencv2\opencv.hpp> #include < opencv2\core.hpp> #include < opencv2\highgui.hpp> #include < opencv2\videoio.hpp> #include < opencv2\imgproc.hpp> #include "DeepDll_B.h" #ifdef _DEBUG #pragma comment(lib, "opencv_core300d.lib") #pragma comment(lib, "opencv_highgui300d.lib") #pragma comment(lib, "opencv_imgcodecs300d.lib") #pragma comment(lib, "opencv_imgproc300d.lib") //line, circle #else #pragma comment(lib, "opencv_core300.lib") #pragma comment(lib, "opencv_highgui300.lib") #pragma comment(lib, "opencv_imgcodecs300.lib") #pragma comment(lib, "opencv_imgproc300.lib") //line, circle //DEEP lib #pragma comment(lib, "MareDeepDLL.lib") #endif using namespace cv; using namespace std; void main() { //DEEP Class MareDeepDll_B cDeep; //load model and structure cDeep.SetNet("lenet_test-memory-1.prototxt", "lenet_iter_10000.caffemodel"); //gpu using on cDeep.GPU_using(); for (int i = 1; i < 14; ++i) { // time check.. unsigned long AAtime = 0, BBtime = 0; AAtime = getTickCount(); //make file name char str[256]; sprintf_s(str, "%d.jpg", i); printf("%s\n", str); //img load and preprocessing Mat img = imread(str); resize(img, img, Size(28, 28)); cvtColor(img, img, CV_BGR2GRAY); //////////// //classify vector< double> rV; //image and class num (caution!! class num is dependented by learning condition.) lenet is classify one number in 10 digits. rV = cDeep.eval(img, 10); ///////////// //result out for (int i = 0; i < rV.size(); i++) { printf("Probability to be Number %d is %.3f\n", i, rV[i]); } // processing time check. BBtime = getTickCount(); printf("%.2lf sec / %.2lf fps\n", (BBtime - AAtime) / getTickFrequency(), 1 / ((BBtime - AAtime) / getTickFrequency())); //draw namedWindow("test", 0); imshow("test", img); waitKey(0); } }...
int main() { VideoCapture cap("rtsp://192.168.0.50"); namedWindow("fish", 0); Mat fishEye; while (1) { cap >> fishEye; if (fishEye.empty()) return 0; imshow("fish", fishEye); if (waitKey(10) > 0) break; } return 0; }...
#include < windows.h> #include < vlc/vlc.h> #include < opencv2\opencv.hpp> #include < opencv2\core.hpp> #include < opencv2\highgui.hpp> #pragma comment(lib, "libvlc.lib") #ifdef _DEBUG #pragma comment(lib, "opencv_core300d.lib") #pragma comment(lib, "opencv_highgui300d.lib") #pragma comment(lib, "opencv_imgproc300d.lib") #pragma comment(lib, "opencv_imgcodecs300d.lib") #else #pragma comment(lib, "opencv_core300.lib") #pragma comment(lib, "opencv_highgui300.lib") #pragma comment(lib, "opencv_imgproc300.lib") #pragma comment(lib, "opencv_imgcodecs300.lib") #endif using namespace cv; using namespace std; struct ctx { Mat* image; HANDLE mutex; uchar* pixels; }; bool isRunning = true; Size getsize(const char* path) { libvlc_instance_t *vlcInstance; libvlc_media_player_t *mp; libvlc_media_t *media; char *vlc_argv[6]; vlc_argv[0] = new char[3]; strcpy_s(vlc_argv[0], 3, "-I"); vlc_argv[1] = new char[6]; strcpy_s(vlc_argv[1], 6, "dummy"); // Don't use any interface vlc_argv[2] = new char[16]; strcpy_s(vlc_argv[2], 16, "--ignore-config"); // Don't use VLC's config vlc_argv[3] = new char[128]; strcpy_s(vlc_argv[3], 128, "--plugin-path=/plugins"); int vlc_argc = 4; vlcInstance = libvlc_new(vlc_argc, vlc_argv); for (int i = 0; i < vlc_argc; i++) delete[] vlc_argv[i]; media = libvlc_media_new_location(vlcInstance, path); mp = libvlc_media_player_new_from_media(media); libvlc_media_release(media); libvlc_video_set_callbacks(mp, NULL, NULL, NULL, NULL); libvlc_video_set_format(mp, "RV24", 100, 100, 100 * 24 / 8); // pitch = width * BitsPerPixel / 8 //libvlc_video_set_format(mp, "RV32", 100, 100, 100 * 4); libvlc_media_player_play(mp); Sleep(2000);//wait a while so that something get rendered so that size info is available unsigned int width = 640, height = 480; for (int i = 0; i < 30 && height == 0; i++) { Sleep(50); libvlc_video_get_size(mp, 0, &width, &height); if (width != 0 && height != 0) break; } if (width == 0 || height == 0) { width = 640; height = 480; } libvlc_media_player_stop(mp); libvlc_release(vlcInstance); libvlc_media_player_release(mp); return Size(width, height); } void *lock(void *data, void**p_pixels) { struct ctx *ctx = (struct ctx*)data; WaitForSingleObject(ctx->mutex, INFINITE); *p_pixels = ctx->pixels; return NULL; } void display(void *data, void *id){ (void)data; assert(id == NULL); } void unlock(void *data, void *id, void *const *p_pixels) { struct ctx *ctx = (struct ctx*)data; Mat frame = *ctx->image; if (frame.data) { imshow("frame", frame); if (waitKey(1) == 27) { isRunning = false; //exit(0); } } ReleaseMutex(ctx->mutex); } int main() { string url = "rtsp://..."; //vlc sdk does not know the video size until it is rendered, so need to play it a bit so that size is known Size sz = getsize(url.c_str()); // VLC pointers libvlc_instance_t *vlcInstance; libvlc_media_player_t *mp; libvlc_media_t *media; char *vlc_argv[6]; vlc_argv[0] = new char[3]; strcpy_s(vlc_argv[0], 3, "-I"); vlc_argv[1] = new char[6]; strcpy_s(vlc_argv[1], 6, "dummy"); // Don't use any interface vlc_argv[2] = new char[16]; strcpy_s(vlc_argv[2], 16, "--ignore-config"); // Don't use VLC's config vlc_argv[3] = new char[128]; strcpy_s(vlc_argv[3], 128, "--plugin-path=/plugins"); int vlc_argc = 4; vlcInstance = libvlc_new(vlc_argc, vlc_argv); for (int i = 0; i < vlc_argc; i++) delete[] vlc_argv[i]; media = libvlc_media_new_location(vlcInstance, url.c_str()); mp = libvlc_media_player_new_from_media(media); libvlc_media_release(media); struct ctx* context = (struct ctx*)malloc(sizeof(*context)); context->mutex = CreateMutex(NULL, FALSE, NULL); context->image = new Mat(sz.height, sz.width, CV_8UC3); context->pixels = (unsigned char *)context->image->data; libvlc_video_set_callbacks(mp, lock, unlock, display, context); libvlc_video_set_format(mp, "RV24", sz.width, sz.height, sz.width * 24 / 8); // pitch = width * BitsPerPixel / 8 //libvlc_video_set_format(mp, "RV32", sz.width, sz.height, sz.width * 4); libvlc_media_player_play(mp); while (isRunning) { //imshow("rtsp", *(context->image)); Sleep(1); } libvlc_media_player_stop(mp); libvlc_release(vlcInstance); libvlc_media_player_release(mp); free(context); return 0; }
#include < iostream> #include "opencv2\objdetect\objdetect.hpp" #include "opencv2\highgui\highgui.hpp" #include "opencv2\imgproc\imgproc.hpp" #include "opencv2\cudaobjdetect.hpp" #include "opencv2\cudaimgproc.hpp" #ifdef _DEBUG #pragma comment(lib, "opencv_core300d.lib") #pragma comment(lib, "opencv_highgui300d.lib") #pragma comment(lib, "opencv_imgcodecs300d.lib") #pragma comment(lib, "opencv_objdetect300d.lib") #pragma comment(lib, "opencv_imgproc300d.lib") #pragma comment(lib, "opencv_cudaobjdetect300d.lib") #else #pragma comment(lib, "opencv_core300.lib") #pragma comment(lib, "opencv_highgui300.lib") #pragma comment(lib, "opencv_imgcodecs300.lib") #pragma comment(lib, "opencv_objdetect300.lib") #pragma comment(lib, "opencv_imgproc300.lib") #pragma comment(lib, "opencv_cudaobjdetect300.lib") #endif using namespace std; using namespace cv; void main() { //for time measure float TakeTime; unsigned long Atime, Btime; //window namedWindow("origin"); //load image Mat img = imread("sh.jpg"); Mat grayImg; //adaboost detection is gray input only. cvtColor(img, grayImg, CV_BGR2GRAY); //load xml file string trainface = ".\\haarcascade_frontalface_alt.xml"; //declaration Ptr< cuda::CascadeClassifier> cascade_gpu = cuda::CascadeClassifier::create(trainface); ///////////////////////////////////////////// //gpu case face detection code cuda::GpuMat faceBuf_gpu; cuda::GpuMat GpuImg; vector< Rect> faces; GpuImg.upload(grayImg); Atime = getTickCount(); cascade_gpu->detectMultiScale(GpuImg, faceBuf_gpu); cascade_gpu->convert(faceBuf_gpu, faces); Btime = getTickCount(); TakeTime = (Btime - Atime) / getTickFrequency(); printf("detected face(gpu version) =%d / %lf sec take.\n", faces.size(), TakeTime); Mat faces_downloaded; if (faces.size() >= 1) { for (size_t i = 0; i < faces.size(); ++i) rectangle(img, faces[i], Scalar(255)); } ///////////////////////////////////////////////// //result display imshow("origin", img); waitKey(0); }
#include < iostream> #include < opencv2\opencv.hpp> #include < opencv2\highgui.hpp> #include < opencv2\imgcodecs.hpp> #include < opencv2\core.hpp> #include < opencv2\imgproc.hpp> #include < opencv2\text.hpp> #include < opencv2/features2d.hpp> #ifdef _DEBUG #pragma comment(lib, "opencv_core300d.lib") #pragma comment(lib, "opencv_highgui300d.lib") #pragma comment(lib, "opencv_imgcodecs300d.lib") #pragma comment(lib, "opencv_text300d.lib") #pragma comment(lib, "opencv_features2d300d.lib") #pragma comment(lib, "opencv_imgproc300d.lib") #else #pragma comment(lib, "opencv_core300.lib") #pragma comment(lib, "opencv_highgui300.lib") #pragma comment(lib, "opencv_imgcodecs300.lib") #pragma comment(lib, "opencv_text300.lib") #pragma comment(lib, "opencv_features2d300.lib") #pragma comment(lib, "opencv_imgproc300d.lib") #endif using namespace std; using namespace cv; void groups_draw(Mat &src, vector< Rect> &groups); void main() { Mat inImg = imread(".\\scenetext01.jpg"); vector< Mat> channels; text::computeNMChannels(inImg, channels); int cn = (int)channels.size(); // Append negative channels to detect ER- (bright regions over dark background) for (int c = 0; c < cn - 1; c++) channels.push_back(255 - channels[c]); Ptr< text::ERFilter> er_filter1 = text::createERFilterNM1(text::loadClassifierNM1(".\\trained_classifierNM1.xml"), 16, 0.00015f, 0.13f, 0.2f, true, 0.1f); Ptr< text::ERFilter> er_filter2 = text::createERFilterNM2(text::loadClassifierNM2(".\\trained_classifierNM2.xml"), 0.5); vector< vector< text::ERStat> > regions(channels.size()); for (int c = 0; c< (int)channels.size(); c++) { er_filter1->run(channels[c], regions[c]); er_filter2->run(channels[c], regions[c]); } // Detect character groups cout << "Grouping extracted ERs ... "; vector< vector< Vec2i> > region_groups; vector< Rect> groups_boxes; text::erGrouping(inImg, channels, regions, region_groups, groups_boxes, text::ERGROUPING_ORIENTATION_HORIZ); groups_draw(inImg, groups_boxes); imshow("grouping", inImg); waitKey(0); } void groups_draw(Mat &src, vector< Rect> &groups) { for (int i = (int)groups.size() - 1; i >= 0; i--) { if (src.type() == CV_8UC3) rectangle(src, groups.at(i).tl(), groups.at(i).br(), Scalar(0, 255, 255), 3, 8); else rectangle(src, groups.at(i).tl(), groups.at(i).br(), Scalar(255), 3, 8); } }///
#include < iostream> #include < opencv2\opencv.hpp> #include < opencv2\highgui.hpp> #include < opencv2\imgcodecs.hpp> #include < opencv2\core.hpp> #include < opencv2\imgproc.hpp> #include < opencv2\text.hpp> #include < opencv2/features2d.hpp> #ifdef _DEBUG #pragma comment(lib, "opencv_core300d.lib") #pragma comment(lib, "opencv_highgui300d.lib") #pragma comment(lib, "opencv_imgcodecs300d.lib") #pragma comment(lib, "opencv_text300d.lib") #pragma comment(lib, "opencv_features2d300d.lib") #pragma comment(lib, "opencv_imgproc300d.lib") #else #pragma comment(lib, "opencv_core300.lib") #pragma comment(lib, "opencv_highgui300.lib") #pragma comment(lib, "opencv_imgcodecs300.lib") #pragma comment(lib, "opencv_text300.lib") #pragma comment(lib, "opencv_features2d300.lib") #pragma comment(lib, "opencv_imgproc300d.lib") #endif using namespace std; using namespace cv; void main() { Mat inImg = imread("M:\\____videoSample____\\SceneText\\SceneText01.jpg"); Mat textImg; cvtColor(inImg, textImg, CV_BGR2GRAY); //Extract MSER vector< vector< Point> > contours; vector< Rect> bboxes; Ptr< MSER> mser = MSER::create(21, (int)(0.00002*textImg.cols*textImg.rows), (int)(0.05*textImg.cols*textImg.rows), 1, 0.7); mser->detectRegions(textImg, contours, bboxes); for (int i = 0; i < bboxes.size(); i++) { rectangle(inImg, bboxes[i], CV_RGB(0, 255, 0)); } namedWindow("t"); imshow("t", inImg); waitKey(0); }
#include < stdio.h> #include < opencv2\opencv.hpp> #include < opencv2/core/core.hpp> #include < opencv2/highgui/highgui.hpp> #include < opencv2\nonfree\features2d.hpp > #ifdef _DEBUG #pragma comment(lib, "opencv_core249d.lib") #pragma comment(lib, "opencv_imgproc249d.lib") //MAT processing #pragma comment(lib, "opencv_objdetect249d.lib") //HOGDescriptor #pragma comment(lib, "opencv_features2d249d.lib") #pragma comment(lib, "opencv_highgui249d.lib") #pragma comment(lib, "opencv_video249d.lib") #else #pragma comment(lib, "opencv_core249.lib") #pragma comment(lib, "opencv_imgproc249.lib") #pragma comment(lib, "opencv_objdetect249.lib") #pragma comment(lib, "opencv_features2d249.lib") #pragma comment(lib, "opencv_highgui249.lib") #pragma comment(lib, "opencv_video249.lib") #endif using namespace std; using namespace cv; void drawOptFlowMap (const Mat& flow, Mat& cflowmap, int step, const Scalar& color); void main() { Mat prev_im,nex_im,flow; prev_im=imread("1.jpg",0); imshow("previm",prev_im); nex_im=imread("2.jpg",0); imshow("nextim",nex_im); calcOpticalFlowFarneback(prev_im,nex_im,flow,0.5, 1, 12, 2, 7, 1.5, 0); Mat cflow; cvtColor(prev_im, cflow, CV_GRAY2BGR); drawOptFlowMap(flow, cflow, 10, CV_RGB(0, 255, 0)); imshow("OpticalFlowFarneback", cflow); waitKey(0); } void drawOptFlowMap (const Mat& flow, Mat& cflowmap, int step, const Scalar& color) { for(int y = 0; y < cflowmap.rows; y += step) for(int x = 0; x < cflowmap.cols; x += step) { const Point2f& fxy = flow.at< Point2f>(y, x); line(cflowmap, Point(x,y), Point(cvRound(x+fxy.x), cvRound(y+fxy.y)), color); circle(cflowmap, Point(cvRound(x+fxy.x), cvRound(y+fxy.y)), 1, color, -1); } }...
#include < stdio.h> #include < iostream> #include < opencv2\opencv.hpp> #include < opencv2\core.hpp> #include < opencv2\highgui.hpp> #include < opencv2\cudaarithm.hpp> #include < opencv2\xfeatures2d\cuda.hpp> #include < opencv2\cudafeatures2d.hpp> //#include < opencv2\xfeatures2d\nonfree.hpp> #ifdef _DEBUG #pragma comment(lib, "opencv_core300d.lib") #pragma comment(lib, "opencv_highgui300d.lib") #pragma comment(lib, "opencv_imgcodecs300d.lib") #pragma comment(lib, "opencv_cudafeatures2d300d.lib") #pragma comment(lib, "opencv_xfeatures2d300d.lib") #pragma comment(lib, "opencv_features2d300d.lib") #else #pragma comment(lib, "opencv_core300.lib") #pragma comment(lib, "opencv_highgui300.lib") #pragma comment(lib, "opencv_imgcodecs300.lib") #pragma comment(lib, "opencv_cudafeatures2d300.lib") #pragma comment(lib, "opencv_xfeatures2d300.lib") #pragma comment(lib, "opencv_features2d300.lib") #endif using namespace cv; using namespace std; void main() { cuda::GpuMat img1(imread("M:\\____videoSample____\\Image\\A2.jpg", CV_LOAD_IMAGE_GRAYSCALE)); cuda::GpuMat img2(imread("M:\\____videoSample____\\Image\\A3.jpg", CV_LOAD_IMAGE_GRAYSCALE)); ///////////////////////////////////////////////////////////////////////////////////////// unsigned long t_AAtime = 0, t_BBtime = 0; float t_pt; float t_fpt; t_AAtime = getTickCount(); ///////////////////////////////////////////////////////////////////////////////////////// cuda::SURF_CUDA surf(400); // detecting keypoints & computing descriptors cuda::GpuMat keypoints1GPU, keypoints2GPU; cuda::GpuMat descriptors1GPU, descriptors2GPU; surf(img1, cuda::GpuMat(), keypoints1GPU, descriptors1GPU); surf(img2, cuda::GpuMat(), keypoints2GPU, descriptors2GPU); cout << "FOUND " << keypoints1GPU.cols << " keypoints on first image" << endl; cout << "FOUND " << keypoints2GPU.cols << " keypoints on second image" << endl; // matching descriptors vector< vector< DMatch> > matches; Ptr< cuda::DescriptorMatcher > matcher = cuda::DescriptorMatcher::createBFMatcher(); matcher->knnMatch(descriptors1GPU, descriptors2GPU, matches, 2); // downloading results Gpu -> Cpu vector< KeyPoint> keypoints1, keypoints2; vector< float> descriptors1, descriptors2; surf.downloadKeypoints(keypoints1GPU, keypoints1); surf.downloadKeypoints(keypoints2GPU, keypoints2); //surf.downloadDescriptors(descriptors1GPU, descriptors1); //surf.downloadDescriptors(descriptors2GPU, descriptors2); vector< KeyPoint> matchingKey1, matchingKey2; std::vector< DMatch > good_matches; for (int k = 0; k < min(descriptors1GPU.rows - 1, (int)matches.size()); k++) { if ((matches[k][0].distance < 0.6*(matches[k][1].distance)) && ((int)matches[k].size() <= 2 && (int)matches[k].size()>0)) { good_matches.push_back(matches[k][0]); } } t_BBtime = getTickCount(); t_pt = (t_BBtime - t_AAtime) / getTickFrequency(); t_fpt = 1 / t_pt; printf("feature extraction = %.4lf / %.4lf \n", t_pt, t_fpt); // drawing the results Mat img_matches; Mat img11, img22; img1.download(img11); img2.download(img22); //drawMatches(img11, matchingKey1, img22, matchingKey2, good_matches, img_matches); drawMatches(img11, keypoints1, img22, keypoints2, good_matches, img_matches); namedWindow("matches", 0); imshow("matches", img_matches); waitKey(0); matcher.release(); }
#include < iostream> #include < opencv2\opencv.hpp> #include < opencv2\videoio.hpp> #include < opencv2\highgui.hpp> //#include < opencv2\core\cuda.hpp> #include < opencv2\core.hpp> //#include < opencv2\bgsegm.hpp> #include < opencv2\cudabgsegm.hpp> #ifdef _DEBUG #pragma comment(lib, "opencv_core300d.lib") #pragma comment(lib, "opencv_highgui300d.lib") #pragma comment(lib, "opencv_videoio300d.lib") #pragma comment(lib, "opencv_cudabgsegm300d.lib") #else #pragma comment(lib, "opencv_core300.lib") #pragma comment(lib, "opencv_highgui300.lib") #pragma comment(lib, "opencv_videoio300.lib") #pragma comment(lib, "opencv_cudabgsegm300.lib") #endif using namespace std; using namespace cv; int main() { // VideoCapture cap("M:\\____videoSample____\\blog\\video20.wmv"); //VideoCapture cap("M:\\____videoSample____\\posco\\cartype1.avi"); // Ptr< cuda::BackgroundSubtractorMOG2 > MOG2_g = cuda::createBackgroundSubtractorMOG2(3000, 64); Mat Mog_Mask; cuda::GpuMat Mog_Mask_g; // Mat o_frame; cuda::GpuMat o_frame_gpu; cap >> o_frame; if (o_frame.empty()) return 0; ///////////////////////////////////////////////////////////////////////// unsigned long AAtime = 0, BBtime = 0; //Mat rFrame; Mat showMat_r_blur; Mat showMat_r; namedWindow("origin"); namedWindow("mog_mask"); while (1) { ///////////////////////////////////////////////////////////////////////// cap >> o_frame; if (o_frame.empty()) return 0; o_frame_gpu.upload(o_frame); AAtime = getTickCount(); // MOG2_g->apply(o_frame_gpu, Mog_Mask_g, -1); //pMOG2_g.operator()(o_frame_gpu, Mog_Mask_g, -1); // Mog_Mask_g.download(Mog_Mask); BBtime = getTickCount(); float pt = (BBtime - AAtime) / getTickFrequency(); float fpt = 1 / pt; printf("gpu %.4lf / %.4lf \n", pt, fpt); o_frame_gpu.download(showMat_r); imshow("origin", showMat_r); imshow("mog_mask", Mog_Mask); ///////////////////////////////////////////////////////////////////////// if (waitKey(10) > 0) break; } MOG2_g.release(); return 0; }...
#include < iostream> #include < opencv2\opencv.hpp> #include < opencv2\highgui.hpp> //#include < opencv2\imgcodecs.hpp> #include < opencv2\videoio.hpp> #include < opencv2\core\cuda.hpp> #include < opencv2\imgproc.hpp> #include < opencv2\cudawarping.hpp> #include < opencv2\cudaimgproc.hpp> //#include < opencv2\cudaarithm.hpp> #include < opencv2\cudaoptflow.hpp> #ifdef _DEBUG #pragma comment(lib, "opencv_core300d.lib") #pragma comment(lib, "opencv_highgui300d.lib") //#pragma comment(lib, "opencv_imgcodecs300d.lib") //imread #pragma comment(lib, "opencv_videoio300d.lib") //video capture #pragma comment(lib, "opencv_imgproc300d.lib") //line, circle #pragma comment(lib, "opencv_cudawarping300d.lib") //cuda::resize #pragma comment(lib, "opencv_cudaimgproc300.lib") //cuda::cvtcolor #pragma comment(lib, "opencv_cudaarithm300d.lib") //cuda::farnebackOpticalFlow #pragma comment(lib, "opencv_cudaoptflow300d.lib") #else #pragma comment(lib, "opencv_core300.lib") #pragma comment(lib, "opencv_highgui300.lib") //#pragma comment(lib, "opencv_imgcodecs300.lib") //imread #pragma comment(lib, "opencv_videoio300.lib") //video capture #pragma comment(lib, "opencv_imgproc300.lib") // //line, circle #pragma comment(lib, "opencv_cudawarping300.lib") //cuda::resize #pragma comment(lib, "opencv_cudaimgproc300.lib") //cuda::cvtcolor #pragma comment(lib, "opencv_cudaarithm300.lib") //cuda::farnebackOpticalFlow #pragma comment(lib, "opencv_cudaoptflow300.lib") #endif using namespace std; using namespace cv; void drawOptFlowMap_gpu(const Mat& flow_xy, Mat& cflowmap, int step, const Scalar& color); int main() { int s = 1; unsigned long AAtime = 0, BBtime = 0; //variables Mat GetImg, flow_x, flow_y, next, prvs, flow_xy; //gpu variable cuda::GpuMat prvs_gpu, next_gpu, flow_x_gpu, flow_y_gpu, flow_xy_gpu; cuda::GpuMat prvs_gpu_o, next_gpu_o; cuda::GpuMat prvs_gpu_c, next_gpu_c; //file name char fileName[100] = "M:\\____videoSample____\\Rendering\\Wildlife.avi"; //video file open VideoCapture stream1(fileName); //0 is the id of video device.0 if you have only one camera if (!(stream1.read(GetImg))) //get one frame form video return 0; //gpu upload, resize, color convert prvs_gpu_o.upload(GetImg); cuda::resize(prvs_gpu_o, prvs_gpu_c, Size(GetImg.size().width / s, GetImg.size().height / s)); cuda::cvtColor(prvs_gpu_c, prvs_gpu, CV_BGR2GRAY); //dense optical flow Ptr< cuda::FarnebackOpticalFlow > fbOF = cuda::FarnebackOpticalFlow::create(); //unconditional loop while (true) { if (!(stream1.read(GetImg))) //get one frame form video break; /////////////////////////////////////////////////////////////////// //gpu upload, resize, color convert next_gpu_o.upload(GetImg); cuda::resize(next_gpu_o, next_gpu_c, Size(GetImg.size().width / s, GetImg.size().height / s)); cuda::cvtColor(next_gpu_c, next_gpu, CV_BGR2GRAY); /////////////////////////////////////////////////////////////////// AAtime = getTickCount(); //dense optical flow fbOF->calc(prvs_gpu, next_gpu, flow_xy_gpu); BBtime = getTickCount(); float pt = (BBtime - AAtime) / getTickFrequency(); float fpt = 1 / pt; printf("%.2lf / %.2lf \n", pt, fpt); //copy for vector flow drawing Mat cflow; resize(GetImg, cflow, Size(GetImg.size().width / s, GetImg.size().height / s)); flow_xy_gpu.download(flow_xy); drawOptFlowMap_gpu(flow_xy, cflow, 10, CV_RGB(0, 255, 0)); imshow("OpticalFlowFarneback", cflow); /////////////////////////////////////////////////////////////////// //Display gpumat next_gpu.download(next); prvs_gpu.download(prvs); imshow("next", next); imshow("prvs", prvs); //prvs mat update prvs_gpu = next_gpu.clone(); if (waitKey(5) >= 0) break; } return 0; } void drawOptFlowMap_gpu(const Mat& flow_xy, Mat& cflowmap, int step, const Scalar& color) { for (int y = 0; y < cflowmap.rows; y += step) for (int x = 0; x < cflowmap.cols; x += step) { Point2f fxy; fxy.x = cvRound(flow_xy.at< Vec2f >(y, x)[0] + x); fxy.y = cvRound(flow_xy.at< Vec2f >(y, x)[1] + y); cv::line(cflowmap, Point(x, y), Point(fxy.x, fxy.y), color); cv::circle(cflowmap, Point(fxy.x, fxy.y), 1, color, -1); } }
#include < iostream> #include < opencv2\opencv.hpp> #include < opencv2\videoio.hpp> #include < opencv2\highgui.hpp> #ifdef _DEBUG #pragma comment(lib, "opencv_core300d.lib") #pragma comment(lib, "opencv_highgui300d.lib") #pragma comment(lib, "opencv_videoio300d.lib") #else #pragma comment(lib, "opencv_core300.lib") #pragma comment(lib, "opencv_highgui300.lib") #pragma comment(lib, "opencv_videoio300.lib") #endif using namespace std; using namespace cv; void main() { Mat test; cv::VideoCapture cap("M:\\____videoSample____\\posco\\cartype1.avi");//0); namedWindow("t"); while(1) { cap >> test; if( test.empty() ) break; imshow("t", test); if( waitKey(10) > 0) break; } }
#include < iostream> #include < opencv2\opencv.hpp> #include < opencv2\highgui.hpp> #include < opencv2\imgcodecs.hpp> #ifdef _DEBUG #pragma comment(lib, "opencv_core300d.lib") #pragma comment(lib, "opencv_highgui300d.lib") #pragma comment(lib, "opencv_imgcodecs300d.lib") #else #pragma comment(lib, "opencv_core300.lib") #pragma comment(lib, "opencv_highgui300.lib") #pragma comment(lib, "opencv_imgcodecs300.lib") #endif using namespace std; using namespace cv; void main() { Mat test; test = imread("M:\\____videoSample____\\torso\\Positive1.png"); namedWindow("t"); imshow("t", test); waitKey(0); }
#pragma once // OpenCVDLL.h #ifdef OPENCVDLL_EXPORTS #define OPENCVDLL_API __declspec(dllexport) #else #define OPENCVDLL_API __declspec(dllimport) #endif #include < opencv2\opencv.hpp> #ifdef _DEBUG #pragma comment(lib, "opencv_core249d.lib") #pragma comment(lib, "opencv_imgproc249d.lib") //MAT processing #else #pragma comment(lib, "opencv_core249.lib") #pragma comment(lib, "opencv_imgproc249.lib") #endif namespace opencvdll_mare { class OPENCVDLL_API OpenCVDLL { public: OpenCVDLL(void); ~OpenCVDLL(void); cv::Mat convert(cv::Mat& inMat); }; }
#include "OpenCVDLL.h" namespace opencvdll_mare { OpenCVDLL::OpenCVDLL(void) { } OpenCVDLL::~OpenCVDLL(void) { } cv::Mat OpenCVDLL::convert(cv::Mat& inMat) { cv::Mat cMat; cv::Sobel(inMat, cMat, inMat.depth(), 1, 0); return cMat; } }
#include < iostream> using namespace std; #include < opencv2\opencv.hpp> #include "OpenCVDLL.h" #ifdef _DEBUG #pragma comment(lib, "opencv_highgui249d.lib") #else #pragma comment(lib, "opencv_highgui249.lib") #endif using namespace cv; void main() { Mat test = imread("AA.jpg"); imshow("test",test); opencvdll_mare::OpenCVDLL cOpenCVDLL_test; Mat outmat = cOpenCVDLL_test.convert(test); imshow("dll test", outmat); waitKey(0); }...