Extract cow number from image

前端 未结 5 2024
庸人自扰
庸人自扰 2020-12-13 07:13

every now and then my mom has to shift through these type of photos to extract the number from the image and rename it to the number.

5条回答
  •  温柔的废话
    2020-12-13 08:11

    I really liked this problem but I am unfamiliar with OpenCV and Python, so I present a partial solution in Matlab. The idea is the important part, and the code is just for reference. I think using my image processing possibly augmented with mark's windowing idea could give you favorable results.

    These images have a ton of vegetation in them and vegetation is typically high in greens and reds. I process only the blue channel which removes a lot of the vegetation and still leaves the white signs easily identifiable. I then use otsus method for thresholding something like this in OpenCV cv::threshold(im_gray, img_bw, 0, 255, CV_THRESH_BINARY | CV_THRESH_OTSU); but then I take 1.5 times the given threshold. so the threshold is still image specific by otsu, but also very selective. At this point you have a pretty good image.

    Then we just clean the image with some erosion and dilation. Also note that that my dilation element is slightly larger than my erosion one. You then have images with fairly clean numbers. Maybe tesserect could even just process the image at this point, or you can try it with the windowing.

    I know OpenCV has these same functions, but as I said I just did what I was familiar with. I hope it helps you. here are my results:

    processed images

    and the code

    %382 is 255*1.5 so basically we are taking the auto threshold and raising it by
    %50 percent. graythresh is performing otsu thresholding
    bim = im(:,:,3) > graythresh(im(:,:,3))*382;
    bim1 = im1(:,:,3) > graythresh(im1(:,:,3))*382;
    bim2 = im2(:,:,3) > graythresh(im2(:,:,3))*382;
    
    %se and se2 are what opencv would call getStructuringElement using a 
    %MORPH_ELLIPSE
    se = strel('disk',3);
    eim = imerode(bim,se);
    eim1 = imerode(bim1,se);
    eim2 = imerode(bim2,se);
    
    %se and se2 are what opencv would call getStructuringElement using a 
    %MORPH_ELLIPSE
    se2 = strel('disk',5);
    dim = imdilate(eim,se2);
    dim1 = imdilate(eim1,se2);
    dim2 = imdilate(eim2,se2);
    
    subplot(3,3,1);imshow(bim);title('blue thresholded');
    subplot(3,3,2);imshow(bim1);title('');
    subplot(3,3,3);imshow(bim2);title('');
    
    subplot(3,3,4);imshow(eim);title('after errosion');
    subplot(3,3,5);imshow(eim1);title('');
    subplot(3,3,6);imshow(eim2);title('');
    
    subplot(3,3,7);imshow(dim);title('after dilation');
    subplot(3,3,8);imshow(dim1);title('');
    subplot(3,3,9);imshow(dim2);title('');
    

提交回复
热议问题