j'ai besoin d'aide pour comprendre ce problème ce que j'ai en ce moment. J'ai 3 images qui sont les mêmes que les différentes choses, c'est qu'ils représentent bleu, vert et rouge. Je dois les combiner et récupérer une image colorée. J'utilise opencv et C++, mais maintenant j'ai ce problème que je n'arrive pas à comprendre.dérivé Calculer le 1er Sobel une fois en x et une fois dans la direction y et combiner ces deux (pour chaque canal)
Nécessaires: travaillant sur la détection de bord.
---- ---- Mise à jour j'ai écrit un nouveau code de
Sobel(img_r, x, CV_16S, 1, 0);
Sobel(img_r, y, CV_16S, 0, 1);
//Compute the L1 norm
sobel_L1_norm = abs(x)+abs(y);
//Find Sobel max value
minMaxLoc(sobel_L1_norm, &min, &max);
sobel_L1_norm.convertTo(sobel_image, CV_32F, 255.0/(max - min), -min * 255.0/(max - min));
threshold(sobel_image, edgeThreshold, min, 255, THRESH_BINARY);
edgeThreshold.copyTo(img_r_edge);
Je reçois ce résultat bad example
Mais il devrait être comme ça. correct one
---- CODE COMPLET -----
Mat img_r = imread(input_path + "/01.png", CV_LOAD_IMAGE_GRAYSCALE);
Mat img_g = imread(input_path + "/02.png", CV_LOAD_IMAGE_GRAYSCALE);
Mat img_b = imread(input_path + "/03.png", CV_LOAD_IMAGE_GRAYSCALE);
// Edge Images
Mat img_r_edge = Mat::zeros(img_r.size(), CV_8UC1);
Mat img_g_edge = Mat::zeros(img_g.size(), CV_8UC1);
Mat img_b_edge = Mat::zeros(img_b.size(), CV_8UC1);
std::cout << "Step 1 - calculating edge images... ";
// TODO: 1) Calculate the 1st Sobel derivative once in x and once in y direction and combine these two
// (for every channel).
Mat x;
Mat y;
Mat abs_x;
Mat abs_y;
Mat sobel_L1_norm;
Mat sobel_image;
Mat edgeThreshold;
double min, max; //Finding min and max Sobel valuye;
//---------------------------------------------------
Sobel(img_r, x, CV_16S, 1, 0);
Sobel(img_r, y, CV_16S, 0, 1);
//Compute the L1 norm
sobel_L1_norm = abs(x)+abs(y);
//Find Sobel max value
minMaxLoc(sobel_L1_norm, &min, &max);
sobel_L1_norm.convertTo(sobel_image, CV_32F, 255.0/(max - min), -min * 255.0/(max - min));
threshold(sobel_image, edgeThreshold, min, 255, THRESH_BINARY);
edgeThreshold.copyTo(img_r_edge);
//----------------------------------------------------
// 2) Normalize every gradient image and convert the results to CV_8UC1.
// 3) Threshold the retrieved (normalized) gradient images using the parameter "edgeThreshold".
// 4) Save the results in the cv::Mats below.
imwrite(out_r_edge_filename, sobel);
imwrite(out_g_edge_filename, img_g_edge);
imwrite(out_b_edge_filename, img_b_edge);
_How_-vous les combiner?Je calcule la «magnitude» pour chaque image grise, puis j'ajoute la magnitude 3. (Utilisez les images flottantes pour éviter l'écrêtage) – Miki
Il devrait fonctionner avec la fonction addWeighted.But je suis vraiment sans aucune idée en ce moment – twistedhat
J'ai posté et répondre avec quelques exemples. Notez que j'écris le code sans vraiment l'essayer, il peut y avoir des erreurs ... mais vous devez comprendre l'idée – Miki