I have recently upgraded from MATLAB R2016a to R2017a (also changed from Windows 7, now using Windows 10). Trying to run my existing code (nothing changed) using VideoWriter to create a video object, I'm getting the following error, when I get to the stage of writing the video:
Error using VideoWriter/writeVideo (line 369)
One or more properties of the video is invalid. Ensure 'Quality' and 'FrameRate' property of the object and the frame dimensions are within allowed range.
This is my code to save the video:
v = VideoWriter('vidOutput','MPEG-4');
v.FrameRate = 240;
open(v);
for i = 1:size(data,2)
... code that plots an image frame...
F = getframe;
pause(0.000001)
writeVideo(v,F.cdata);
end
The issue seems to be with the FrameRate property. When it's set to more than 150, the error happens. Anything lower than 150 runs ok. Important to note, that when running on MATLAB R2016a, it did work with FrameRate = 240.
Any idea what might have gone wrong?
Related
I'm trying to use roipoly(I) to allow user selection of a region within an image. When I run the example code from MATLAB documentation:
img = imread('eight.tif')
imshow(img)
bw = roipoly(img)
I'm getting the following error:
Undefined function or variable 'iptPointerManager'.
with several other error lines after, but i'm quite convinced that the one above is the issue.
I have MATLAB R2016a on Windows 7 with image processing toolbox installed and working.
Resetting the path using restoredefaultpath worked.
I'm trying to get this Matlab example from the MathWorks site to work with Octave 4.0.0:
http://www.mathworks.com/help/vision/examples/motion-based-multiple-object-tracking.html
I made a GitHub repository for what I have so far, which mostly a re-formatted version of the MathWorks link above:
https://github.com/MicrocontrollersAndMore/Matlab_Octave_Multiple_Object_Tracking
The only changes I have made so far are:
-Made a separate main.m file to run multiObjectTracking.m
-Since I don't have the 'atrium.avi' file used by MathWorks, I changed the VideoFileReader line in the code to use '768x576.avi', which is included with OpenCV ('768x576.avi' is also uploaded to the GitHub repo linked above)
-Minor spacing and comment changes
-added "pkg load image;" at the beginning of main.m and multiObjectTracking.m, in the few test Octave computer vision programs I did this seemed to be necessary, otherwise I would get an error to the effect of "library image has been installed but not loaded"
Currently when I run the program I get the following error:
error: 'vision' undefined near line 38 column 18
error: called from
multiObjectTracking>setupSystemObjects at line 38 column 16
multiObjectTracking at line 14 column 7
main at line 14 column 1
In other words in the function:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function obj = setupSystemObjects()
% initialize Video I/O, create objects for reading a video from a file, drawing the tracked objects in each frame, and playing the video
obj.reader = vision.VideoFileReader('768x576.avi'); % create a video file reader
obj.videoPlayer = vision.VideoPlayer('Position', [20, 400, 700, 400]); % create two video players, one to display the video,
obj.maskPlayer = vision.VideoPlayer('Position', [740, 400, 700, 400]); % and one to display the foreground mask
% Create System objects for foreground detection and blob analysis
% The foreground detector is used to segment moving objects from the background. It outputs a binary mask, where the pixel value
% of 1 corresponds to the foreground and the value of 0 corresponds to the background
obj.detector = vision.ForegroundDetector('NumGaussians', 3, 'NumTrainingFrames', 40, 'MinimumBackgroundRatio', 0.7);
% Connected groups of foreground pixels are likely to correspond to moving objects. The blob analysis System object is used to find such groups
% (called 'blobs' or 'connected components'), and compute their characteristics, such as area, centroid, and the bounding box.
obj.blobAnalyser = vision.BlobAnalysis('BoundingBoxOutputPort', true, 'AreaOutputPort', true, 'CentroidOutputPort', true, 'MinimumBlobArea', 400);
end
The 'vision' object is not recognized.
It is my understanding that 'vision' is part of the Matlab Toolbox, but I am unable to confirm this since I don't have access to Matlab.
So here are my questions so far:
-Is there an Octave equivalent of the 'vision' object?
-What other differences should I be aware of to get this Matlab program running under Octave ??
I have been attempting to use the following site:
http://www.peterkovesi.com/matlabfns/
but have not been very successful so far getting these examples working or as a guide to the Matlab to Octave translation I'm attempting.
Any assistance from Octave experts or those who have gotten computer vision working in both Matlab and Octave would be greatly appreciated.
Those are Matlab functions from the Computer Vision System Toolbox.
General rule is, Octave comes short in matching Matlab toolboxes and when it has something, you need to install the Octave packages separately.
The link to the site you supplied does not seem to provide support for vision object functionalities.
I'm trying to create a movie in Matlab where I run through my code several times, and the output of each runthrough is added to the video. However, I keep getting a strange error when I actually try to add the frame to the movie. Here's a snippet of my code:
writerobj = VideoWriter('RHI_P.avi');
writerobj.FrameRate = 60;
open(writerobj);
\\ Runs through code and generates a pcolor figure
figure(14);
\\ Plotting script goes here....
fig = figure;
F = getframe(fig);
writerobj = writeVideo(writerobj,F);
>> Error using VideoWriter/writeVideo: Too many output arguments.
However, if I look at 'help writeVideo', it says this: "writeVideo(OBJ,FRAME) writes a FRAME to the video file associated with OBJ."
From my point of view (though I could be wrong!), I'm following the example given. I've been stuck on this for a couple days now. Does anyone have any advice?
Also, I've been using getframe(gcf) as a workaround for now. However, I can't keep doing that, because my code takes several days to run, and gcf captures the screensaver once that kicks on.
writeVideo does not have an output argument which is what the error states.
You just need to say
writeVideo(writerObj, F);
Hope this helps.
i searched face detection for matlab to my project.
i found one:
http://people.kyb.tuebingen.mpg.de/kienzle/fdlib/fdlib.htm
i downloaded the source code, but it didn't work, i got that error from matlab:
??? Undefined function or method 'fdmex' for input arguments of type
'uint8'.
Error in ==> tinytest at 10 s = fdmex(x', threshold);
the main script is:
x = imread('geeks.jpg');
% decision threshold.
% change this to a smaller value, if too many false detections occur.
% change it to a larger value, if faces are not recognized.
% a reasonable range is -10 ... 10.
threshold = 0;
imagesc(x); hold on; colormap gray;
s = fdmex(x', threshold);
for i=1:size(s,1)
h = rectangle('Position',[s(i,1)-s(i,3)/2,s(i,2)-s(i,3)/2,s(i,3),s(i,3)], ...
'EdgeColor', [1,0,0], 'linewidth', 2);
end
axis equal;
axis off
can you find the error?
Usually when I see a uint8 error and a grayscale image, its a red flag to me that I need to do
colorImg=imread('imageName.jpg')
% Even if the image is grayscale, if its png or jpg,
% it will load in as a color image almost exclusively
img=rgb2gray(colorImg)
If you look at the img output, you will notice now its of type double instead of uint8 :)
If that doesn't work, hopefully macduffs will, mine just seems easier if that actually does fix it. :)
Depending on your version of matlab, it looks like the fdlib, comes with a .dll, rename it to .mexw32 or whatever your host machine desires. You can determine this by running:
>> mexext
mexw32
on the Matlab command prompt. Use the mex extension and rename the fdmex.dll to fdmex.mexw32, or whatever mexext returns and it should run flawlessly.
If I run in on my Windows XP machine, I get that beautiful picure:
However, if you do not have a 32 bit machine, the author of the software writes on the link in the question:
Please note that all builds were optimized for Intel Pentium CPUs. If
you would like to run it on a different platform, or have any other
questions, please let me know.
He has a link to his profile and email, so I recommend contacting him for a 64 bit version of the executable.
If you have a recent version of Matlab with the Computer Vision System Toolbox installed, you can use vision.CascadeObjectDetector system object to detect faces in images.
I encounter a strange problem with quad function.
I was using quad to calculate simple integral, and it worked for 10 to 20 times, then Matlab issues the following error:
Error using quad (line 75)
The integrand function must return an output vector of the same length as the input vector.
yteor(k) = quad(#(q)(exp(-(q).^2).*q.^2/(k.^2+1)), 0, 1);
Here q and k are scalars.
I can not get what is wrong and why it worked several hours ago.
Edit
Here is my code
for k=1:100,
xteor(k)=step*k;
yteor(k)=quad(#(q)(exp(-(q).^2).*q.^2/((step.*k+1).^2)),0,1);
end plot(xteor,yteor,'r');
The following snippet works for me on Octave (Matlab GNU clone)
step = 1;
xteor = zeros(100,1);
yteor = zeros(100,1);
for k=1:100,
xteor(k)=step*k;
yteor(k)=quad(#(q)(exp(-(q).^2).*q.^2/((step.*k+1).^2)),0,1);
end
plot(xteor,yteor,'r');
pause
My hypothesis is that your error is the consequence of something else happening earlier in your code (maybe related to step not being a scalar?). Instead of focusing on this line where the error arise. Try to search what you have changed just before the error appear.