Skip to content

Commit

Permalink
Fix spelling, spacing, and unused variables (opencv#236)
Browse files Browse the repository at this point in the history
* Fix spelling, spacing, and unused variables

* Fixed typo in 3 more models

* Added open back

* Remove setBackendAndTarget functions from C++ demos, which are unused functionality.
  • Loading branch information
ryan1288 authored Feb 29, 2024
1 parent 80ef421 commit a45b893
Show file tree
Hide file tree
Showing 11 changed files with 13 additions and 58 deletions.
7 changes: 0 additions & 7 deletions models/face_detection_yunet/demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@ class YuNet
model = cv::FaceDetectorYN::create(model_path_, "", input_size_, conf_threshold_, nms_threshold_, top_k_, backend_id_, target_id_);
}

void setBackendAndTarget(int backend_id, int target_id)
{
backend_id_ = backend_id;
target_id_ = target_id;
model = cv::FaceDetectorYN::create(model_path_, "", input_size_, conf_threshold_, nms_threshold_, top_k_, backend_id_, target_id_);
}

/* Overwrite the input size when creating the model. Size format: [Width, Height].
*/
void setInputSize(const cv::Size& input_size)
Expand Down
2 changes: 1 addition & 1 deletion models/image_classification_mobilenet/demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ int main(int argc, char** argv)
else
cap.open(0);
if (!cap.isOpened())
CV_Error(Error::StsError, "Cannot opend video or file");
CV_Error(Error::StsError, "Cannot open video or file");
Mat frame, blob;
static const std::string kWinName = model;
int nbInference = 0;
Expand Down
9 changes: 2 additions & 7 deletions models/object_detection_nanodet/demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ class NanoDet
{
this->strides = { 8, 16, 32, 64 };
this->net = readNet(modelPath);
setBackendAndTarget(bId, tId);
this->net.setPreferableBackend(bId);
this->net.setPreferableTarget(tId);
this->project = Mat::zeros(1, this->regMax + 1, CV_32F);
for (size_t i = 0; i <= this->regMax; ++i)
{
Expand All @@ -57,12 +58,6 @@ class NanoDet
this->generateAnchors();
}

void setBackendAndTarget(Backend bId, Target tId)
{
this->net.setPreferableBackend(bId);
this->net.setPreferableTarget(tId);
}

Mat preProcess(const Mat& inputImage)
{
Image2BlobParams paramNanodet;
Expand Down
2 changes: 1 addition & 1 deletion models/object_detection_nanodet/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def vis(preds, res_img, letterbox_scale, fps=None):
img = vis(preds, image, letterbox_scale)

if args.save:
print('Resutls saved to result.jpg\n')
print('Results saved to result.jpg\n')
cv.imwrite('result.jpg', img)

if args.vis:
Expand Down
12 changes: 2 additions & 10 deletions models/object_detection_yolox/demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,6 @@ class YoloX {
this->generateAnchors();
}

void setBackendAndTarget(dnn::Backend bId, dnn::Target tId)
{
this->backendId = bId;
this->targetId = tId;
this->net.setPreferableBackend(this->backendId);
this->net.setPreferableTarget(this->targetId);
}

Mat preprocess(Mat img)
{
Mat blob;
Expand Down Expand Up @@ -137,7 +129,7 @@ class YoloX {
boxesXYXY[r].height = boxes_xyxy.at<float>(r, 3);
}

vector< int > keep;
vector<int> keep;
NMSBoxesBatched(boxesXYXY, maxScores, maxScoreIdx, this->confThreshold, this->nmsThreshold, keep);
Mat candidates(int(keep.size()), 6, CV_32FC1);
int row = 0;
Expand Down Expand Up @@ -282,7 +274,7 @@ int main(int argc, char** argv)
else
cap.open(0);
if (!cap.isOpened())
CV_Error(Error::StsError, "Cannot opend video or file");
CV_Error(Error::StsError, "Cannot open video or file");
Mat frame, inputBlob;
double letterboxScale;

Expand Down
2 changes: 1 addition & 1 deletion models/object_detection_yolox/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def vis(dets, srcimg, letterbox_scale, fps=None):
img = vis(preds, image, letterbox_scale)

if args.save:
print('Resutls saved to result.jpg\n')
print('Results saved to result.jpg\n')
cv.imwrite('result.jpg', img)

if args.vis:
Expand Down
11 changes: 1 addition & 10 deletions models/person_detection_mediapipe/demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,6 @@ class MPPersonDet {
this->anchors = getMediapipeAnchor();
}

void setBackendAndTarget(dnn::Backend bId, dnn::Target tId)
{
this->backendId = bId;
this->targetId = tId;
this->net.setPreferableBackend(this->backendId);
this->net.setPreferableTarget(this->targetId);
}

pair<Mat, Size> preprocess(Mat img)
{
Mat blob;
Expand Down Expand Up @@ -237,10 +229,9 @@ int main(int argc, char** argv)
backendTargetPairs[backendTargetid].first, backendTargetPairs[backendTargetid].second);
//! [Open a video file or an image file or a camera stream]
if (!cap.isOpened())
CV_Error(Error::StsError, "Cannot opend video or file");
CV_Error(Error::StsError, "Cannot open video or file");

static const std::string kWinName = "MPPersonDet Demo";
int nbInference = 0;
while (waitKey(1) < 0)
{
cap >> frame;
Expand Down
20 changes: 2 additions & 18 deletions models/pose_estimation_mediapipe/demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,6 @@ class MPPersonDet {
this->anchors = getMediapipeAnchor();
}

void setBackendAndTarget(dnn::Backend bId, dnn::Target tId)
{
this->backendId = bId;
this->targetId = tId;
this->net.setPreferableBackend(this->backendId);
this->net.setPreferableTarget(this->targetId);
}

pair<Mat, Size> preprocess(Mat img)
{
Mat blob;
Expand Down Expand Up @@ -124,7 +116,7 @@ class MPPersonDet {
{
rotBoxes[i] = Rect2d(Point2d(boxes.at<float>(i, 0), boxes.at<float>(i, 1)), Point2d(boxes.at<float>(i, 2), boxes.at<float>(i, 3)));
}
vector< int > keep;
vector<int> keep;
NMSBoxes(rotBoxes, score, this->scoreThreshold, this->nmsThreshold, keep, 1.0f, this->topK);
if (keep.size() == 0)
return Mat();
Expand Down Expand Up @@ -179,14 +171,6 @@ class MPPose {
this->personBoxEnlargeFactor = 1.25;
}

void setBackendAndTarget(dnn::Backend bId, dnn::Target tId)
{
this->backendId = bId;
this->targetId = tId;
this->net.setPreferableBackend(this->backendId);
this->net.setPreferableTarget(this->targetId);
}

tuple<Mat, Mat, float, Mat, Size> preprocess(Mat image, Mat person)
{
/***
Expand Down Expand Up @@ -567,7 +551,7 @@ int main(int argc, char** argv)
MPPose poseEstimator(model, confThreshold, backendTargetPairs[backendTargetid].first, backendTargetPairs[backendTargetid].second);
//! [Open a video file or an image file or a camera stream]
if (!cap.isOpened())
CV_Error(Error::StsError, "Cannot opend video or file");
CV_Error(Error::StsError, "Cannot open video or file");

static const std::string kWinName = "MPPose Demo";
while (waitKey(1) < 0)
Expand Down
2 changes: 1 addition & 1 deletion models/text_detection_ppocr/demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ int main(int argc, char** argv)
else
cap.open(0);
if (!cap.isOpened())
CV_Error(Error::StsError, "Cannot opend video or file");
CV_Error(Error::StsError, "Cannot open video or file");
Mat originalImage;
static const std::string kWinName = modelName;
while (waitKey(1) < 0)
Expand Down
2 changes: 1 addition & 1 deletion models/text_recognition_crnn/demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ int main(int argc, char** argv)
else
cap.open(0);
if (!cap.isOpened())
CV_Error(Error::StsError, "Cannot opend video or file");
CV_Error(Error::StsError, "Cannot open video or file");
Mat originalImage;
static const std::string kWinName = modelPath;
while (waitKey(1) < 0)
Expand Down
2 changes: 1 addition & 1 deletion models/text_recognition_crnn/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def visualize(image, boxes, texts, color=(0, 255, 0), isClosed=True, thickness=2

# Save results if save is true
if args.save:
print('Resutls saved to result.jpg\n')
print('Results saved to result.jpg\n')
cv.imwrite('result.jpg', original_image)

# Visualize results in a new window
Expand Down

0 comments on commit a45b893

Please sign in to comment.