【发布时间】:2019-09-16 08:02:41
【问题描述】:
我目前正在开发一个扑克牌检测程序。我正在使用霍夫线变换来检测卡片的位置,因为这似乎是最可靠的方法。因为它较少依赖环境条件,例如光线和背景(我认为),而不是寻找轮廓。
我用这张图来测试:
在转换之后,我得到了这个结果:
如您所见,线条并没有闭合多边形,我无法对卡片的位置做出任何结论。
我已经考虑过使用一些标准(例如角度等)来对属于同一张卡片的线条进行分组,但我想知道是否有更好更快的方法来找到每张卡片的位置。
我使用了这个代码:
#include <cstdlib>
#include <cstdio>
#include "detector.h"
#include "data_structs.h"
#include <unistd.h>
#define MIN_LINE_LEN 80
#define MAX_LINE_GAP 10
//Variáveis globais
Mat img;
Mat src;
int main( int argc, char** argv ){
src = imread("img.jpg");
src.copyTo(img);
preProcessImg();
detectCards();
return 0;
}
//Prepara a img para ser analisada
void preProcessImg(){
Mat aux_gray;
cvtColor(img, aux_gray, CV_BGR2GRAY); // Convert the image to grayscale
GaussianBlur(aux_gray, img, Size(5,5), 0);
}
void detectCards(){
vector<Vec4i> lines;
//Detetar as linhas
Canny(img, img, 30, 200);
HoughLinesP(img, lines, 1, CV_PI/180, 80, MIN_LINE_LEN, MAX_LINE_GAP);
}
【问题讨论】:
标签: c++ image opencv image-processing computer-vision