I want to draw the edges of tomatoes in crate. For this I'm using Canny edge detection algorithm. The problem with it is that in a crate some of the tomatoes are over the top of the other as shown in the figure bellow:
As one can see some of the tomatoes have more light over them than the other, due to this the result by Canny is as follows:
As one can see Canny is not able to detect the edges of the tomatoes at the end of the crate where the light is low in the original image.
Does anyone have any solution to this ? (It's not possible to get uniform light on all the tomatoes, but if there is some algorithm that can do that would be really helpful.)
Here is my OpenCV code:
#include <opencv2/opencv.hpp>
using namespace cv;
Mat img, img_gray, img_value, fz, fg, I, pre, cost, vis, G, img_draw, in_que, skip, img_canny;
int main(){
std::string filepath = "/Users/vedanshu/Desktop/IMG_5207.JPG";
img = imread(filepath);
cvtColor(img, img_gray, cv::COLOR_BGRA2GRAY);
img_gray.copyTo(img_value);
GaussianBlur(img_value, img_value, Size(3, 3), 0, 0, BORDER_DEFAULT);
Canny(img_gray, img_canny, 50, 50);
imwrite( "/Users/vedanshu/Desktop/test_canny.png", img_canny );
}