Last active
September 25, 2016 14:23
-
-
Save jyoshida-sci/ddefc41dab63d51f9617 to your computer and use it in GitHub Desktop.
Opencv_webcom_samples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "opencv2\opencv.hpp" | |
#ifdef _WIN64 | |
#ifdef _DEBUG | |
#pragma comment(lib,"C:\\opencv\\opencv2411\\build\\x64\\vc10\\lib\\opencv_core2411d.lib") | |
#pragma comment(lib,"C:\\opencv\\opencv2411\\build\\x64\\vc10\\lib\\opencv_imgproc2411d.lib") | |
#pragma comment(lib,"C:\\opencv\\opencv2411\\build\\x64\\vc10\\lib\\opencv_highgui2411d.lib") | |
#pragma comment(lib,"C:\\opencv\\opencv2411\\build\\x64\\vc10\\lib\\opencv_ml2411d.lib") | |
#pragma comment(lib,"C:\\opencv\\opencv2411\\build\\x64\\vc10\\lib\\opencv_objdetect2411d.lib") | |
#else | |
#pragma comment(lib,"C:\\opencv\\opencv2411\\build\\x64\\vc10\\lib\\opencv_core2411.lib") | |
#pragma comment(lib,"C:\\opencv\\opencv2411\\build\\x64\\vc10\\lib\\opencv_imgproc2411.lib") | |
#pragma comment(lib,"C:\\opencv\\opencv2411\\build\\x64\\vc10\\lib\\opencv_highgui2411.lib") | |
#pragma comment(lib,"C:\\opencv\\opencv2411\\build\\x64\\vc10\\lib\\opencv_ml2411.lib") | |
#pragma comment(lib,"C:\\opencv\\opencv2411\\build\\x64\\vc10\\lib\\opencv_objdetect2411.lib") | |
#endif | |
#else | |
#ifdef _DEBUG | |
#pragma comment(lib,"C:\\opencv\\opencv2411\\build\\x86\\vc10\\lib\\opencv_core2411d.lib") | |
#pragma comment(lib,"C:\\opencv\\opencv2411\\build\\x86\\vc10\\lib\\opencv_imgproc2411d.lib") | |
#pragma comment(lib,"C:\\opencv\\opencv2411\\build\\x86\\vc10\\lib\\opencv_highgui2411d.lib") | |
#pragma comment(lib,"C:\\opencv\\opencv2411\\build\\x86\\vc10\\lib\\opencv_ml2411d.lib") | |
#pragma comment(lib,"C:\\opencv\\opencv2411\\build\\x86\\vc10\\lib\\opencv_objdetect2411d.lib") | |
#else | |
#pragma comment(lib,"C:\\opencv\\opencv2411\\build\\x86\\vc10\\lib\\opencv_core2411.lib") | |
#pragma comment(lib,"C:\\opencv\\opencv2411\\build\\x86\\vc10\\lib\\opencv_imgproc2411.lib") | |
#pragma comment(lib,"C:\\opencv\\opencv2411\\build\\x86\\vc10\\lib\\opencv_highgui2411.lib") | |
#pragma comment(lib,"C:\\opencv\\opencv2411\\build\\x86\\vc10\\lib\\opencv_ml2411.lib") | |
#pragma comment(lib,"C:\\opencv\\opencv2411\\build\\x86\\vc10\\lib\\opencv_objdetect2411.lib") | |
#endif | |
#endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "opencv2/opencv.hpp" | |
int main(int argh, char* argv[]) | |
{ | |
cv::VideoCapture cap(0); | |
cap.set(CV_CAP_PROP_FRAME_WIDTH, 1000); | |
cap.set(CV_CAP_PROP_FRAME_HEIGHT, 1000); | |
cap.set(CV_CAP_PROP_FPS, 100); | |
cap.set(CV_CAP_PROP_FORMAT, CV_8UC1); | |
if (!cap.isOpened()) | |
{ | |
return -1; | |
} | |
int cnt = 0; | |
int oldcnt = 0; | |
int64 nowTime = 0; | |
int64 diffTime = 0; | |
int fps = 0; | |
const double f = (1000 / cv::getTickFrequency()); | |
int64 startTime = cv::getTickCount(); | |
while (1) | |
{ | |
//calc FPS | |
nowTime = cv::getTickCount(); | |
diffTime = (int)((nowTime - startTime)*f); | |
if (diffTime >= 1000) { | |
startTime = nowTime; | |
fps = cnt - oldcnt; | |
oldcnt = cnt; | |
} | |
std::ostringstream os; | |
os << fps << "Frames/sec"; | |
std::string number = os.str(); | |
//original img | |
cv::Mat img; | |
cap >> img; | |
cv::Mat img0 = img.clone(); | |
cv::putText(img0, number, cv::Point(50, 100), cv::FONT_HERSHEY_SIMPLEX, 1, cv::Scalar(255, 255, 255), 2, CV_AA); | |
cv::imshow("camera", img0); | |
int key = cv::waitKey(1); | |
if (key == 113)//q | |
{ | |
break; | |
} | |
else if (key == 115) | |
{ | |
cv::imwrite("img.png", img); | |
} | |
cnt++; | |
} | |
cv::destroyAllWindows(); | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "..\opencv.h" | |
#include <vector> | |
int main( int argc, char **argv ) | |
{ | |
cv::VideoCapture cap; | |
cap.open(1); | |
cv::namedWindow("camera", CV_WINDOW_AUTOSIZE|CV_WINDOW_FREERATIO); | |
while ( 1 ) { | |
cv::Mat img; | |
cap >> img; | |
cv::Mat img0 = img.clone(); | |
cv::imshow("camera", img0); | |
char ch = cv::waitKey(30); | |
if ( ch == 27 ) break;// press [Esc] | |
} | |
cv::destroyAllWindows(); | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "..\opencv.h" | |
#include <vector> | |
int main( int argc, char **argv ) | |
{ | |
//http://opencv.jp/cookbook/opencv_img.html | |
std::string cascadeName = "C:\\opencv\\opencv2411\\build\\share\\OpenCV\\haarcascades\\haarcascade_frontalface_alt.xml"; | |
cv::CascadeClassifier cascade; | |
if(!cascade.load(cascadeName)) | |
return -1; | |
cv::VideoCapture cap; | |
cap.open(1); | |
cv::namedWindow("camera", CV_WINDOW_AUTOSIZE|CV_WINDOW_FREERATIO); | |
std::vector<cv::Rect> rect_faces; | |
while ( 1 ) { | |
cv::Mat img; | |
cap >> img; | |
cv::Mat img0 = img.clone(); | |
//face detection | |
rect_faces.clear(); | |
cascade.detectMultiScale( | |
img0, | |
rect_faces, | |
1.1, 2, | |
CV_HAAR_SCALE_IMAGE, | |
cv::Size(30, 30)); | |
//image process for each area | |
std::vector<cv::Rect>::const_iterator r = rect_faces.begin(); | |
for(; r != rect_faces.end(); ++r) { | |
cv::rectangle(img0, r->tl(), r->br(), cv::Scalar(200,200,0), 1, CV_AA); | |
cv::Mat mosaic = img0(*r).clone(); | |
cv::resize(mosaic, mosaic, cv::Size(), 0.05, 0.05); | |
cv::resize(mosaic, mosaic, r->size(),0,0,cv::INTER_NEAREST); | |
cv::Mat facearea = img0(*r); | |
mosaic.copyTo(facearea); | |
} | |
cv::imshow("camera", img0); | |
char ch = cv::waitKey(30); | |
if ( ch == 27 ) break;// press [Esc] | |
} | |
cv::destroyAllWindows(); | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "..\opencv.h" | |
#include <vector> | |
//displaying fps | |
//http://iwaki2009.blogspot.jp/2012/08/opencvfps.html | |
int main( int argc, char **argv ) | |
{ | |
cv::VideoCapture cap; | |
cap.open(1); | |
cv::namedWindow("camera", CV_WINDOW_AUTOSIZE|CV_WINDOW_FREERATIO); | |
cv::namedWindow("canny", CV_WINDOW_AUTOSIZE|CV_WINDOW_FREERATIO); | |
int cnt = 0; | |
int oldcnt = 0; | |
int64 nowTime = 0; | |
int64 diffTime = 0; | |
int fps = 0; | |
const double f = (1000 /cv::getTickFrequency()); | |
int64 startTime = cv::getTickCount(); | |
//loop start | |
while ( 1 ) { | |
//calc FPS | |
nowTime = cv::getTickCount(); | |
diffTime = (int)((nowTime- startTime)*f); | |
if (diffTime >= 1000) { | |
startTime = nowTime; | |
fps = cnt - oldcnt; | |
oldcnt = cnt; | |
} | |
std::ostringstream os; | |
os << fps << "Frames/sec"; | |
std::string number = os.str(); | |
//original img | |
cv::Mat img; | |
cap >> img; | |
cv::Mat img0 = img.clone(); | |
cv::imshow("camera", img0); | |
//canny | |
cv::Mat img_canny; | |
cv::resize(img0, img_canny, cv::Size(), 0.5, 0.5); | |
cv::cvtColor(img_canny, img_canny, CV_BGR2GRAY); | |
cv::GaussianBlur( img_canny, img_canny, cv::Size(15, 15), 2, 2 ); | |
cv::Canny( img_canny, img_canny, 5, 50, 3 ); | |
cv::putText(img_canny, number, cv::Point(50,100), cv::FONT_HERSHEY_SIMPLEX, 1, cv::Scalar(255,255,255), 2, CV_AA); | |
cv::imshow("canny", img_canny); | |
//escape | |
char ch = cv::waitKey(30); | |
if ( ch == 27 ) break;// press [Esc] | |
cnt++; | |
} | |
cv::destroyAllWindows(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment