eliminating edges
Hello guys, who tells me how to remove the edges and the center line? So as to have only the characters?
Thank you
Hello guys, who tells me how to remove the edges and the center line? So as to have only the characters?
Thank you
there is many ways to solve this problem.
my proposed solution is using the technique that explained at another question
i applied it only horizontally in the code below
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
using namespace cv;
using namespace std;
int main( int argc, char** argv )
{
Mat src = imread( argv[1] );
if (src.empty())
return -1;
Mat gray,eroded,reduced_w;
cvtColor( src, gray, CV_BGR2GRAY );
erode( gray, eroded, Mat::ones(8,1,CV_8UC1) ); // change of kernel gives different results
reduce( eroded, reduced_w, 1, CV_REDUCE_AVG );
for ( int i = 0; i < src.rows; i++)
{
if( reduced_w.at<uchar>(0,i) < 100)
line( gray,Point(0,i),Point(gray.cols,i),Scalar(255,255,255),3);
}
vector< vector <Point> > contours;
eroded = gray < 127;
findContours( eroded, contours,CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE );
eroded = Scalar(255);
for( size_t i = 0; i< contours.size(); i++ )
{
Rect r = boundingRect(contours[i]);
if((contourArea( contours[i] ) > 200) & r.x > 5 & r.x + r.width < gray.cols - 5 )
{
rectangle( eroded, Point(r.x,r.y), Point(r.x+r.width,r.y+r.height), Scalar(0), -1 );
rectangle( src, Point(r.x,r.y), Point(r.x+r.width,r.y+r.height), Scalar(0,0,255), 2 );
}
}
gray = gray + eroded;
imshow("result", gray );
imshow("color result", src );
waitKey(0);
return 0;
}
Result images:
-
pi@raspberrypi:~/app $ g++ linee.c++ -o linee -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_objdetect linee.c++: In function ‘int main(int, char**)’: linee.c++:17:35: error: ‘REDUCE_AVG’ was not declared in this scope reduce( eroded, reduced_w, 1, REDUCE_AVG );
Switch the rows and cols in the Mat::ones() and change the direction of the reduce.
@sturkmen: I do not understand what you mean. @Tetragramm: I reversed as you say. From Mat::ones(8,1,CV_8UC1) to Mat::ones(1,8,????) but I do not know what to put in the place of CV_8UC1
Asked: 2016-02-26 13:46:51 -0600
Seen: 1,633 times
Last updated: Feb 26 '16
Weird result while finding angle
Sobel derivatives in the 45 and 135 degree direction
Saving an image with unset pixels
Object recognition by edge (or corners) matching ?
How to detect square in a video using c++ and opencv?
phase correlation for image registration(image stitching)
What is the easiest way to display a cv::Mat in a decoration free full-screen window?
Look for erode and dilate. May be you can use this post
I would use Erode and Dilate to remove the little bits around the edge, then shrink your bounding box to the white pixels only, which should get rid of the outside edge. Then remove any row that has no white in it to get rid of the center line. Then dilate again to get any bits that didn't get removed because of rotation or whatever.