Skip to content
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

Fix Visual C++ 2013 runtime error in debug mode #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/preprocessing.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#define PREPROCESSING_H

//Function prototypes
cv::Mat binary_threshold(cv::Mat input, float threshold_value, int min, int max);
cv::Mat binary_threshold(cv::Mat input, float threshold_value, uchar min, uchar max);
cv::Mat make_background_black(cv::Mat input, int white_level);
cv::Mat filter_red_channel(cv::Mat input, int new_value);
cv::Mat filter_red_channel(cv::Mat input, uchar new_value);
bool is_red_suit_by_corners(cv::Mat input, int base_threshold, int target_regions, float perc_red);

#endif
2 changes: 1 addition & 1 deletion include/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ int max(int a, int b, int c, int d);
int min(int a, int b);
int dist_manhattan(int x1, int x2, int y1, int y2);
bool is_in_image(int x, int y, int width, int height);
double round(double d);
double round_(double d);

#endif
4 changes: 2 additions & 2 deletions src/card.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
using namespace std;

// Initialise corner Rects
const cv::Rect Card::TOP_CORNER_RECT = cv::Rect(5, 5, 0.15F * Card::WIDTH - 5, 0.28F * Card::HEIGHT - 5);
const cv::Rect Card::BOTTOM_CORNER_RECT = cv::Rect(Card::WIDTH - 0.15F * Card::WIDTH - 5, Card::HEIGHT - 0.28F * Card::HEIGHT - 5, 0.15F * Card::WIDTH, 0.28F * Card::HEIGHT);
const cv::Rect Card::TOP_CORNER_RECT = cv::Rect(5, 5, static_cast<int>(0.15F * Card::WIDTH - 5), static_cast<int>(0.28F * Card::HEIGHT - 5));
const cv::Rect Card::BOTTOM_CORNER_RECT = cv::Rect(static_cast<int>(Card::WIDTH - 0.15F * Card::WIDTH - 5), static_cast<int>(Card::HEIGHT - 0.28F * Card::HEIGHT - 5), static_cast<int>(0.15F * Card::WIDTH), static_cast<int>(0.28F * Card::HEIGHT));
const int Card::CORNER_AREA = Card::TOP_CORNER_RECT.area();

// Initialise colours
Expand Down
2 changes: 1 addition & 1 deletion src/cl_own.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ cv::Mat binary_operation(cv::Mat input, int mode, int element_size)
int half = (element_size - 1) / 2;

//For all X x Y pixels
int result = 0;
uchar result = 0;
for(int y = 0; y < input.rows; y++)
{
for(int x = 0; x < input.cols; x++)
Expand Down
16 changes: 8 additions & 8 deletions src/classification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,9 @@ void detect_value_picture(Card *card)
}

//Do matches using colour info integration
matches[JACK] += (int)round(hit_or_miss_score(mat_rank_1c, se_symbols[JACK]) * 100.0F);
matches[QUEEN] += (int)round(hit_or_miss_score(mat_rank_1c, se_symbols[QUEEN]) * 100.0F);
matches[KING] += (int)round(hit_or_miss_score(mat_rank_1c, se_symbols[KING]) * 100.0F);
matches[JACK] += (int)round_(hit_or_miss_score(mat_rank_1c, se_symbols[JACK]) * 100.0F);
matches[QUEEN] += (int)round_(hit_or_miss_score(mat_rank_1c, se_symbols[QUEEN]) * 100.0F);
matches[KING] += (int)round_(hit_or_miss_score(mat_rank_1c, se_symbols[KING]) * 100.0F);

cv::imshow("input", mat_rank_1c);
cv::imshow("template", se_symbols[QUEEN]); //Only relevant for threecards.jpg
Expand Down Expand Up @@ -390,13 +390,13 @@ void find_suit_sym(Card *card)
//Do matches using colour info integration
if(card->detected_colour == Card::RED)
{
matches[DIAMOND] += (int)round(hit_or_miss_score(mat_sym_1c, se_symbols[DIAMOND]) * 100.0F);
matches[HEART] += (int)round(hit_or_miss_score(mat_sym_1c, se_symbols[HEART]) * 100.0F);
matches[DIAMOND] += (int)round_(hit_or_miss_score(mat_sym_1c, se_symbols[DIAMOND]) * 100.0F);
matches[HEART] += (int)round_(hit_or_miss_score(mat_sym_1c, se_symbols[HEART]) * 100.0F);
}
else if(card->detected_colour == Card::BLACK)
{
matches[CLUB] += (int)round(hit_or_miss_score(mat_sym_1c, se_symbols[CLUB]) * 100.0F);
matches[SPADE] += (int)round(hit_or_miss_score(mat_sym_1c, se_symbols[SPADE]) * 100.0F);
matches[CLUB] += (int)round_(hit_or_miss_score(mat_sym_1c, se_symbols[CLUB]) * 100.0F);
matches[SPADE] += (int)round_(hit_or_miss_score(mat_sym_1c, se_symbols[SPADE]) * 100.0F);
}
else
{
Expand Down Expand Up @@ -456,7 +456,7 @@ float hit_or_miss_score(cv::Mat img, cv::Mat se_image)
in_channels = img.channels(),
se_channels = se_image.channels();

int total = img.rows * img.cols;
// int total = img.rows * img.cols;

//For each position, try and find a match
int matched_pixels = 0;
Expand Down
24 changes: 12 additions & 12 deletions src/isolation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,15 @@ void find_squares(cv::Mat image, vector<vector<cv::Point> >& squares, int thresh
vector<cv::Point> approx;
bool is_duplicate_contour = false;
bool is_inside_another = false;
int min_square_diff_rel = (image_size.width + image_size.height) * 0.5F * min_square_diff;
int min_square_diff_rel = static_cast<int>((image_size.width + image_size.height) * 0.5F * min_square_diff);

// test each contour
for(size_t i = 0; i < contours.size(); i++)
{
// approximate contour
cv::approxPolyDP(cv::Mat(contours[i]), approx, cv::arcLength(cv::Mat(contours[i]), true)*0.02, true);

int area = fabs(cv::contourArea(cv::Mat(approx)));
int area = static_cast<int>(fabs(cv::contourArea(cv::Mat(approx))));

if( approx.size() == 4 && //4 corners
area > (image_size.width * image_size.height * 0.04F) && //Area larger than 0.04 of the image in pixels
Expand All @@ -152,7 +152,7 @@ void find_squares(cv::Mat image, vector<vector<cv::Point> >& squares, int thresh
for (int i = 0; i < 4; ++i)
{
vector<cv::Point> square = squares[j];
rotate(&square[0], &square[i], &square[4]);
rotate(square.begin(), square.begin() + i, square.end());
if (square_diff(square, approx) < min_square_diff_rel)
{
is_duplicate_contour = true;
Expand Down Expand Up @@ -232,23 +232,23 @@ int find_cards(cv::Mat input, vector<Card>* cards)
std::vector<cv::Point2f> quad_pts;
std::vector<cv::Point2f> corners;

for (int i = 0; i < squares.size(); ++i)
for (vector<Card>::size_type i = 0; i < squares.size(); ++i)
{
// Define the destination image
cv::Mat quad = cv::Mat::zeros(Card::HEIGHT, Card::WIDTH, CV_8UC3);

// Corners of the destination image
quad_pts.clear();
quad_pts.push_back(cv::Point2f(0, 0));
quad_pts.push_back(cv::Point2f(quad.cols, 0));
quad_pts.push_back(cv::Point2f(quad.cols, quad.rows));
quad_pts.push_back(cv::Point2f(0, quad.rows));
quad_pts.push_back(cv::Point2f(static_cast<float>(quad.cols), 0));
quad_pts.push_back(cv::Point2f(static_cast<float>(quad.cols), static_cast<float>(quad.rows)));
quad_pts.push_back(cv::Point2f(0, static_cast<float>(quad.rows)));

corners.clear();
corners.push_back(cv::Point2f(squares[i][3].x, squares[i][3].y));
corners.push_back(cv::Point2f(squares[i][2].x, squares[i][2].y));
corners.push_back(cv::Point2f(squares[i][1].x, squares[i][1].y));
corners.push_back(cv::Point2f(squares[i][0].x, squares[i][0].y));
corners.push_back(cv::Point2f(static_cast<float>(squares[i][3].x), static_cast<float>(squares[i][3].y)));
corners.push_back(cv::Point2f(static_cast<float>(squares[i][2].x), static_cast<float>(squares[i][2].y)));
corners.push_back(cv::Point2f(static_cast<float>(squares[i][1].x), static_cast<float>(squares[i][1].y)));
corners.push_back(cv::Point2f(static_cast<float>(squares[i][0].x), static_cast<float>(squares[i][0].y)));

// Get transformation matrix
cv::Mat transmtx = cv::getPerspectiveTransform(corners, quad_pts);
Expand All @@ -272,7 +272,7 @@ int find_cards(cv::Mat input, vector<Card>* cards)
if (whiteness > 0.8F)
{
cv::Mat quad_rot;
rotate(&corners[0], &corners[1], &corners[4]);
rotate(corners.begin(), corners.begin() + 1, corners.end());
cv::Mat transmtx = cv::getPerspectiveTransform(corners, quad_pts);
cv::warpPerspective(input, quad_rot, transmtx, quad.size());

Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ int main(int argc, char **argv)

cout << "Press space to take a photo" << endl;

char key;
int key;
do
{
key = cvWaitKey(10);
Expand Down
4 changes: 2 additions & 2 deletions src/preprocessing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ using namespace std;
* Returns
* cv::Mat: A binary thresholded image matrix
*/
cv::Mat binary_threshold(cv::Mat input, float threshold_value, int min, int max)
cv::Mat binary_threshold(cv::Mat input, float threshold_value, uchar min, uchar max)
{
//Get size
cv::Size input_size = input.size();
Expand Down Expand Up @@ -135,7 +135,7 @@ cv::Mat make_background_black(cv::Mat input, int white_level)
* Returns
* cv::Mat: An image matrix with only the red channel remaining
*/
cv::Mat filter_red_channel(cv::Mat input, int new_value)
cv::Mat filter_red_channel(cv::Mat input, uchar new_value)
{
//Get size
cv::Size input_size = input.size();
Expand Down
2 changes: 1 addition & 1 deletion src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ bool is_in_image(int x, int y, int width, int height)
* Returns:
* double: Nearest integer in double format
*/
double round(double d)
double round_(double d)
{
return floor(d + 0.5);
}