opencv - Bildmultiplikation

Hi, ich versuche ein bisschen mit Mat Class zu spielen. Ich möchte ein Produktelement zwischen zwei Bildern erstellen, den c ++ / opencv-Port von MATLABimmultiply.

Das ist mein Code:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "opencv2/imgproc/imgproc.hpp"

#include <iostream>

using namespace cv;
using namespace std;

Mat imgA, imgB;
Mat imgAB;
Mat product;

void printMinMax(Mat m, string s) {
    double minVal; 
    double maxVal; 
    Point minLoc; 
    Point maxLoc;

    minMaxLoc( m, &minVal, &maxVal, &minLoc, &maxLoc );
    cout << "min val in " << s << ": " << minVal << endl;
    cout << "max val in " << s << ": " << maxVal << endl;
}

int main(int /*argc*/, char** /*argv*/) {

    cout << "OpenCV version: " << CV_MAJOR_VERSION << " " << CV_MINOR_VERSION << endl;

    imgA = imread("test1.jpg"); 
    cout << "original image size: " << imgA.rows << " " << imgA.cols << endl;
    cout << "original type: " << imgA.type() << endl;
    cvtColor(imgA, imgA, CV_BGR2GRAY);
    printMinMax(imgA, "imgA");

    imgB = imread("test2.jpg"); 
    cout << "original image size: " << imgB.rows << " " << imgB.cols << endl;
    cout << "original type: " << imgB.type() << endl;
    cvtColor(imgB, imgB, CV_BGR2GRAY);
    printMinMax(imgB, "imgB");

    namedWindow("originals", CV_WINDOW_AUTOSIZE);
    namedWindow("product", CV_WINDOW_AUTOSIZE);

    imgAB = Mat( max(imgA.rows,imgB.rows), imgA.cols+imgB.cols, imgA.type());
    imgA.copyTo(imgAB(Rect(0, 0, imgA.cols, imgA.rows)));
    imgB.copyTo(imgAB(Rect(imgA.cols, 0, imgB.cols, imgB.rows)));

    product = imgA.mul(imgB);
    printMinMax(product, "product");

    while( true )
    {
        char c = (char)waitKey(10);

        if( c == 27 )
            { break; }

        imshow( "originals", imgAB );
        imshow( "product", product );
    }

    return 0;
}

Hier ist das Ergebnis:

OpenCV version: 2 4
original image size: 500 500
original type: 16
min val in imgA: 99
max val in imgA: 255
original image size: 500 500
original type: 16
min val in imgB: 0
max val in imgB: 255
init done 
opengl support available 
min val in product: 0
max val in product: 255

Ich denke, dass der Maximalwert im Produkt größer als 255 sein muss, aber auf 255 gekürzt wird, da der Typ der beiden Matrizen 16 ist. Ich habe versucht, die Matrizen in CV_32F zu konvertieren, aber der Maximalwert im Produkt ist 64009 (eine Zahl) das verstehe ich nicht)

Antworten auf die Frage(2)

Ihre Antwort auf die Frage