OpenCV Error. Expected Ptr<cv::UMat> for argument '%s', What kind of error is this? - ocr

Below I have provided the snippet of the code
kernel=np.ones((1, 1), np.float32)
img=cv2.dilate(pages[0], kernel, iterations=1)
img=cv2.erode(pages[0], kernel, iterations=1)
text=str(pt.image_to_string(img))
I am getting some errors in the second line of the above code. Thanks in advance!

The error you are getting is because pages[0] is not the right form.
cv2.Umat() is functionally equivalent to np.float32(), so your code should read:
img = cv2.dilate(np.float32(pages[0]), kernel, iterations=1)
img = cv2.erode(np.float32(pages[0]), kernel, iterations=1)

Related

Octave Function Undefined

Any idea why the following produces an error?
printf("this is my text\n");
MyFunc;
function MyFunc
printf("printing from inside function\n");
endfunction
This is the error I get (from the Command Window)
error: 'MyFunc' undefined near line 3, column 3
error: called from
function_example at line 3 column 1
Okay, I see the issue now. The function definition needs to be placed before the function call is made - as shown below.
printf("this is my text\n");
function MyFunc
printf("printing from inside function\n");
endfunction
MyFunc;

error message "The text is too long to be edited" in Expression Builder for a Control Source

Try to put the following in the main report to sum the totals from three sub reports:
=IIf(IsNull([FCR_LABOR_COST subreport].[Report]![Total_Labor_Cost]),0,[FCR_LABOR_COST subreport].[Report]![Total_Labor_Cost])
+IIf(IsNull([FCR_EXPENSES subreport].[Report]![Total_Expenses]),0,[FCR_EXPENSES subreport].[Report]![Total_Expenses])
+IIf(IsNull([FCR_EQUIPMENT subreport].[Report]![Total_Equipment]),0,[FCR_EQUIPMENT subreport].[Report]![Total_Eqipment])
Received the following error message:
The text is too long to be edit.
How do I resolve this? Please advise.
You can shorten it using Nz expressions to achieve the same result -
=Nz([FCR_LABOR_COST subreport].[Report]![Total_Labor_Cost], 0) +
Nz([FCR_EXPENSES subreport].[Report]![Total_Expenses], 0) +
Nz([FCR_EQUIPMENT subreport].[Report]![Total_Equipment], 0)

value of a function that takes an argument which is itself a function

I am trying a simple function as follows:
function out=Y_T(f,a,b)
Y_T=f(a)-f(b)
end
f is an argument which is a function itself. For example f=x^4+3. The function T_Y should evaluate the values of f in 'a' and 'b' and subtract them. But when i try to use this function for example T_Y(x^4+3,5,2) i face with an error: Index exceeds matrix dimension. How can i fix it? Any tips will be appreciated.
Thanks a lot.
I think you simply have your syntax wrong - as written, you're passing the numeric value x^4 + 3 into Y_T. I think what you need is:
Y_T(#(x) x^4 + 3, 5, 2)
This defines an anonymous function, and passes it in to Y_T.
Your definition of Y_T is slightly wrong too - you need to assign the result to out, like so:
function out=Y_T(f,a,b)
out=f(a)-f(b)
end

Error : 'x' undefined

I got a problem with running Octave function (ODE), I've tried already present solutions for this problem but nothing is working. I've also tried by saving my filename as egzamin.m but it too not worked.
Code from octave :
function dx=egzamin(x,t)
dx=zeros(4,1);
b=0;
g=9.81;
x1=x(1);
y1=x(2);
Vx=x(3);
Vy=x(4);
dx(1)=Vx;
dx(2)=Vy;
dx(3)=-b*Vx*sqrt(Vx.^2+Vy.^2);
dx(4)=-b*Vy*sqrt(Vx.^2+Vy.^2)-g;
endfunction
N=mod(291813,100);
x1=0;
y1=0;
Vx=20+N;
Vy=20+N;
t=0:0.01:500;
sol=lsode("egzamin",[x1,y1,Vx,Vy],t);
plot(sol(:,1),sol(:,2))
The error is :
error: 'x' undefined near line 5 column 4
error: called from
egzamin at line 5 column 3
Since the file starts with function, it is not a script file,
as explained in the doc:
Unlike a function file, a script file must not begin with the keyword
function
Add any statement (even dummy like 1;) before the function line to get a script file.
# dummy statement to get a script file instead of a function file
1;
function dx=egzamin(x,t)
g = 9.81;
Vx = x(3);
Vy = x(4);
dx = [Vx, Vy, 0, -g];
endfunction
N=mod(291813,100);
x1=0;
y1=0;
Vx=20+N;
Vy=20+N;
t=0:0.01:500;
sol=lsode("egzamin",[x1,y1,Vx,Vy],t);
plot(sol(:,1),sol(:,2))
A very clear explanation of what's going on is given here.
You need to save the function (thus from function to endfunction and naught else) as egzamin.m, and then execute the rest of the code in a script or at the command line. Alternatively, provided Octave does that the same as what MATLAB does nowadays, first put your script (N=(..) to plot()) and then the function.
This is necessary since you are defining your function first, so it doesn't have any inputs yet, as you don't define them until later. The function needs to have its inputs defined before it executes, hence you need to save your function separately.
You can of course save your "script" bit, thus everything which is currently below your function declaration, as a function as well, simply don't give it in- and outputs, or, set all the input parameters here as well. (Which I wouldn't do as it's the same as your
egzamin then.) e.g.
function []=MyFunc()
N=mod(291813,100);
x1=0;
y1=0;
Vx=20+N;
Vy=20+N;
t=0:0.01:500;
sol=lsode("egzamin",[x1,y1,Vx,Vy],t);
plot(sol(:,1),sol(:,2))
endfunction

How can I use function callback ('StopFcn' , 'TimerFcn' )for audiorecorder object in MATLAB?

I want to execute the function 'get_pitch(samples,fs,winsize,winshift)' while during recording through audiorecorder object. To do that, I found that 'function callback' would be helpful to do that.
So I try to this code.
% assume fs,winsize,winshift is given.
T = 0.1; % in seconds
samples = cell{100,1};
r = audiorecorder(fs,16,1);
k=1;
r.TimerPeriod = 0.1;
r.StopFcn = 'samples{k} = getaudiodata(r);';
r.TimerFcn = {#get_pitch,samples{k},winsize,winshift};
while 1
record(r,T);
k=k+1;
end
But following exception occurs during execution.
1) after record(r,T) is executed. (StopFcn is now called)
??? Error using ==> eval
Undefined function or variable 'r'.
2) after StopFcn is called (TimerFcn is now called)
In this phase, get_pitch function have totally wrong parameters. For example, parameter
in the position samples{k} change to 'audiorecorder object'.
It seems that I do not know exact use of 'StopFcn' & 'TimerFcn'.
Is there anyone who can give me some advice? I really appreciate all of your comments.