-
Notifications
You must be signed in to change notification settings - Fork 26
camera & image detection #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Kozitsin
wants to merge
1
commit into
itseez-academy:master
Choose a base branch
from
Kozitsin:working
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
#include <iostream> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "opencv2/core/core.hpp" | ||
#include "opencv2/highgui/highgui.hpp" | ||
#include "opencv2/objdetect/objdetect.hpp" | ||
|
||
using namespace std; | ||
using namespace cv; | ||
|
||
const char* params = | ||
"{ h | help | false | print usage }" | ||
"{ | detector | | XML file with a cascade detector }" | ||
"{ | image | | image to detect objects on }" | ||
"{ | video | | video file to detect on }" | ||
"{ | camera | false | whether to detect on video stream from camera }"; | ||
|
||
|
||
void drawDetections(const vector<Rect>& detections, | ||
const Scalar& color, | ||
Mat& image) | ||
{ | ||
for (size_t i = 0; i < detections.size(); ++i) | ||
{ | ||
rectangle(image, detections[i], color, 2); | ||
} | ||
} | ||
|
||
const Scalar red(0, 0, 255); | ||
const Scalar green(0, 255, 0); | ||
const Scalar blue(255, 0, 0); | ||
const Scalar colors[] = {red, green, blue}; | ||
|
||
int main(int argc, char** argv) | ||
{ | ||
// Parse command line arguments. | ||
CommandLineParser parser(argc, argv, params); | ||
// If help flag is present, print help message and exit. | ||
if (parser.get<bool>("help")) | ||
{ | ||
parser.printParams(); | ||
return 0; | ||
} | ||
|
||
string detector_file = parser.get<string>("detector"); | ||
CV_Assert(!detector_file.empty()); | ||
string image_file = parser.get<string>("image"); | ||
string video_file = parser.get<string>("video"); | ||
bool use_camera = parser.get<bool>("camera"); | ||
|
||
// Load detector. | ||
CascadeClassifier unnLogoCascade; | ||
CascadeClassifier unnOldLogoCascade; | ||
CascadeClassifier openCVLogoCascade; | ||
CascadeClassifier itseezFullCascade; | ||
CascadeClassifier itseezEyeCascade; | ||
|
||
// TODO: change paths!!! | ||
if (!unnLogoCascade.load(detector_file)) | ||
{ | ||
cout << "UNN not ready!"; | ||
return -1; | ||
} | ||
/*if (!unnOldLogoCascade.load(pathToCascade)) | ||
{ | ||
cout << "UNN old not ready!"; | ||
return -1; | ||
} | ||
if (!openCVLogoCascade.load(pathToCascade)) | ||
{ | ||
cout << "openCV not ready!"; | ||
return -1; | ||
} | ||
if (!itseezFullCascade.load(pathToCascade)) | ||
{ | ||
cout << "itseez full not ready!"; | ||
return -1; | ||
} | ||
if (!itseezEyeCascade.load(pathToCascade)) | ||
{ | ||
cout << "itseez eye not ready!"; | ||
return -1; | ||
}*/ | ||
|
||
|
||
|
||
|
||
if (!image_file.empty()) | ||
{ | ||
// TODO: Detect objects on image. | ||
vector<Rect> unnLogos; | ||
Mat image = imread(image_file); | ||
|
||
unnLogoCascade.detectMultiScale(image, unnLogos); | ||
cout << "Num of images found: " << unnLogos.size() << endl; | ||
} | ||
else if (!video_file.empty()) | ||
{ | ||
// TODO: Detect objects on every frame of a video. | ||
|
||
} | ||
else if (use_camera) | ||
{ | ||
// TODO: Detect objects on a live video stream from camera. | ||
Mat frame; | ||
VideoCapture capture; | ||
capture.open(0); | ||
capture.grab(); | ||
|
||
while (true) | ||
{ | ||
capture >> frame; | ||
|
||
vector<Rect> unnLogos; | ||
unnLogoCascade.detectMultiScale(frame, unnLogos); | ||
cout << unnLogos.size() << endl; | ||
|
||
} | ||
} | ||
|
||
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Этих изменений в ваших коммитах быть не должно.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Я залил их, т.к. вручную менял скриптовый файл. Не синкая с апстримом.