Reading frame after converting Matlab pdollar toolbox code to Octave

眉间皱痕 提交于 2019-12-11 05:38:26

问题


I want to read a video using pdollar toolbox. I have few video files upon whom I am trying to apply the acfDetect classier. However, I don't get the correct output. On checking, I found that the data of the frame (the matrix) do not match, for Matlab and Octave. The question will be clear with the attached pics. I tried to print the value of the frame and this is what I get:

Matlab output:

Octave output:

As a hit an trial, I saw that multiplying Octave values by 255 (RGB max) gives me an approx to the Matlab values. But when I do so, I get the following error:

> >> runonVideos processing 11-50-48--11-50-58_resized.mp4 ... error: rgbConvertMex: For floats all values in I must be smaller than 1. error: called from rgbConvert at line 80 column 2 chnsPyramid at line 133 column 2 acfDetect_modified>acfDetectImg at line 74 column 2 acfDetect_modified at line 41 column 19 pedestrianDetection at line 33 column 11 runonVideos at line 8 column 5

Essentially, Matlab gets the same value (0-255) but doesn't give any such error for the function stated here: rgbConvertMex.I am unable to understand where exactly is the problem.

If I am able to get the same value as in Matlab, my problem will be solved to a large extent.

The Octave code is here:

> % Output text file
    outFile = fopen(['C:\devwork\matlab\boosted\detection\',videoFname(1:end-4),'_detections.txt'],'w+');
    % videoPlayer = vision.VideoPlayer;
    vObj = VideoReader('C:\devwork\matlab\boosted\resizedVideos\11-50-48--11-50-58_resized.mp4');
    %fprintf vObj;
    % videoFwriter = vision.VideoFileWriter('result3_newAnnLdcf+.mp4','FileFormat','MPEG4','FrameRate',vObj.FrameRate);
    tic
    while hasFrame(vObj)

        frame = readFrame(vObj);
        %fprintf(frame);
        % frame = imresize(frame,0.5);
        bbs = acfDetect_modified(frame,detector);
        % displayFrame = frame;
        bbs = bbs(:,1:4);
        bbs = round(bbs);
%         if ((bbs(1,:) >= 1152) || (bbs(2,:) >= 648))
%             disp('BB exceeds bounds')
%             disp(bbs)
%         end
        % displayFrame = insertShape(displayFrame,'Rectangle',bbs,'LineWidth',2,'Color','red'); 
        fprintf(outFile,'%d ',reshape(bbs,numel(bbs),1));
        fprintf(outFile,'\n');
        % videoPlayer.step(displayFrame);
        % step(videoFwriter,displayFrame);
    end
    toc
    fclose(outFile);
    fprintf('done \n');
    % release(videoPlayer);
    % release(videoFwriter);
end

Edit 1: In Matlab, I tried changing v=v*255 to v=uint8(v) But now I get all values as either 0 or 1.

Edit 2:

Screenshot of the code:

Screenshot of the output:

Edit 3: As suggested, code line 31 in Octace was changed to:v=uint8(v*255); This does give result in integers but they are still not same as that of Matlab. I am guessing it must be some issue with my multiplication factor of 255. But this is still not resolved.

Screenshot of the new output:


回答1:


The function you're looking for is im2uint8, which is provided by the image package.

This can take an input of class double in the range [0,1] and convert it to a uint8 image, with corresponding values in the range [0,255] accordingly.



来源:https://stackoverflow.com/questions/44144370/reading-frame-after-converting-matlab-pdollar-toolbox-code-to-octave

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!