java and matlab pixel value

asked 2013-11-19 08:29:16 -0600

itay gravatar image

Hi,

I have got a project in Matlab and I need to convert him to java. The project received a video file, decode him and o some manipulation on the frames.

My problem start in the decoding, I've got a different values of pixels. As example the first frame get the values(123,154,98) in the matlab but in eclipse I've got the values(120, 152, 96).

This is the first part of the matlab and java code that only read the first frame from the file: Matlab:

videoFReader = cv.VideoCapture(currFname);
    videoFReader.set('PosFrames' , startFrame-1); % 0 based numbering


    % Compute the cropping area

    % Initialize a zero matrix, which will contain the maximal gradient in each pixel
    max_G2 = 0; % In Matlab, we simply initialize it to 0, and it will becomse a matrix later.

    % For display purposes
    h = waitbar(0 , 'Computing Cropped Area');

    % Run on each of the relevant frames
    for cF = 1 : (endFrame - startFrame + 1)

        % For display purposes
        if mod(cF , 10) == 0, waitbar(cF / (endFrame - startFrame + 1) , h); end

        currFrame = videoFReader.read;}

Java:

for(int i = 0 ; i < FRAME_SIZE ; i++)
        {
                Mat mainMat = new Mat();
                b = retriever.getFrameAtTime((((i * 28))/30)*1000000,MediaMetadataRetriever.OPTION_CLOSEST);
                //b = retriever.getFrameAtTime(((630 + (i * 28))/30)*1000000,MediaMetadataRetriever.OPTION_CLOSEST);
                mainMat =  new Mat(new Size(b.getWidth(),b.getHeight()),CvType.CV_16UC3);

                Utils.bitmapToMat(b, mainMat);}

I'm sure that is the same frame cause I take the first frame.

What am I missing here?

edit retag flag offensive close merge delete

Comments

Before even looking into the code, are you countering the fact that matlab uses RGB image format and openCV uses the BGR format? This means that R and B channel are swapped and thuis calculation of pixel values could be different if you process them.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-11-20 03:21:47 -0600 )edit

Yes, I look at it, but as you can see the results looks near to each other but not exactly the same.

itay gravatar imageitay ( 2013-11-20 06:17:10 -0600 )edit