图像分割,特征提取,该如何处理
图像分割,特征提取
这么一幅图像 5只是占据了整幅图像的一小部分 希望能够除去不需要的背景 使5能够占据整幅图像的绝大部分空间 请问各位有什么好的idea

------解决方案--------------------
如果你的图都和这张类似的话,要切割还挺简单的
1 : 取threshold,产生binary image
2 : 找contours
3 : 挑选area最大的contour(I)
4 : 根据I取bounding rect
5 : 选取bounding rect所在的区间
这一个case中我不选择lambda而是选择functor
因为寻找maximum的contour可能会比较常用
这一帖对你可能有点帮助
http://qtandopencv.blogspot.com/2013/10/opencv-and-artificial-neural-networkann_30.html
讲述如何抽取numeric numbers,提取特征并利用neural network辨识
------解决方案--------------------
仅供参考
这么一幅图像 5只是占据了整幅图像的一小部分 希望能够除去不需要的背景 使5能够占据整幅图像的绝大部分空间 请问各位有什么好的idea
------解决方案--------------------
如果你的图都和这张类似的话,要切割还挺简单的
1 : 取threshold,产生binary image
2 : 找contours
3 : 挑选area最大的contour(I)
4 : 根据I取bounding rect
5 : 选取bounding rect所在的区间
struct maxContours
{
bool operator()(std::vector<cv::Point> const &a, std::vector<cv::Point> const &b) const
{
return cv::contourArea(a) < cv::contourArea(b);
}
};
try{
cv::Mat input = cv::imread("/Users/Qt/program/blogsCodes/pic/****_char_5.jpg", CV_LOAD_IMAGE_GRAYSCALE);
cv::Mat binary;
cv::threshold(input, binary, 0, 255, CV_THRESH_BINARY_INV + CV_THRESH_OTSU);
using Points = std::vector<cv::Point>;
std::vector<Points> contours;
cv::findContours(binary.clone(), contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);
auto it = std::max_element(std::begin(contours), std::end(contours), maxContours());
cv::Rect const mask_rect = cv::boundingRect(*it);
cv::imshow("", binary(mask_rect));
cv::waitKey();
}catch(std::exception const &ex)
{
std::cerr<<ex.what()<<std::endl;
}
这一个case中我不选择lambda而是选择functor
因为寻找maximum的contour可能会比较常用
这一帖对你可能有点帮助
http://qtandopencv.blogspot.com/2013/10/opencv-and-artificial-neural-networkann_30.html
讲述如何抽取numeric numbers,提取特征并利用neural network辨识
------解决方案--------------------
仅供参考
Dim FPFN As String 'FullPathFileName
Dim i As Integer
Dim t As Integer
Dim n As Integer
Dim x As Integer
Dim x1 As Integer
Dim y As Integer
Dim w As Integer
Dim h As Integer
Dim b As Long
Dim a As Boolean
Dim nm(9) As String
Dim s As String
Dim r As String
Private Sub Form_Load()
FPFN = Command$
If Left(FPFN, 1) = Chr(34) Then FPFN = Mid(FPFN, 2)
If Right(FPFN, 1) = Chr(34) Then FPFN = Left(FPFN, Len(FPFN) - 1)
If Not FileExists(FPFN) Then
logtofile "[" + FPFN + "] file not find!"
End 'form
End If
nm(0) = _
"--OOO---" + _
"-OO-OO--" + _
"-O---O--" + _
"OO---OO-" + _
"OO---OO-" + _
"OO---OO-" + _
"OO---OO-" + _
"OO---OO-" + _
"OO---OO-" + _
"-O---O--" + _
"-OO-OO--" + _
"--OOO---"
nm(1) = _
"--OO----" + _
"OOOO----" + _
"--OO----" + _
"--OO----" + _
"--OO----" + _
"--OO----" + _
"--OO----" + _
"--OO----" + _
"--OO----" + _
"--OO----" + _
"--OO----" + _
"OOOOOO--"
nm(2) = _
"--OOOO--" + _
"-O--OOO-" + _
"O----OO-" + _
"-----OO-" + _
"-----OO-" + _
"-----O--" + _
"----OO--" + _
"----O---" + _
"---O----" + _
"--O----O" + _
"-OOOOOOO" + _
"OOOOOOO-"