Skip to content

Commit b303006

Browse files
committed
Quick rounding fixes
1 parent 68bda7e commit b303006

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

CHANGELOG.TXT

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
2014-08-25 Lcferrum <[email protected]>
1+
2014-08-26 Lcferrum <[email protected]>
22

33
* Release 1.0

README.TXT

+1-2
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ log_file [optional, default: empty string]
9797
it will be created. Relative path is relative to AVS script location.
9898

9999
log_append [optional, default: true]
100-
If true - log file will be appended. If false - log file file will be
101-
truncated.
100+
If true - log file will be appended. If false - log file will be truncated.
102101

103102
interval [optional, default: 1]
104103
Recognition interval in seconds. It means that every N seconds a frame will

src/ocrf.cpp

+12-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const AVS_Linkage *AVS_linkage=NULL;
2929
//Filters are created in order of appearance in AVS file
3030
OCRFilter::OCRFilter(PClip child, const char* log_file, bool log_append, int interval, const char* time_format, bool debug, bool localized_output, bool inverted, const char* threshold, IScriptEnvironment *env):
3131
GenericVideoFilter(child),
32-
fduration((unsigned int)((double)vi.fps_denominator/vi.fps_numerator*1000)), timer(interval*1000), last_frame(-1), time_format(SEC), debug(debug), log_file(), csv_sep(), dec_sep(), neg_sign(), ssocr()
32+
fduration(((double)vi.fps_denominator/vi.fps_numerator*1000)), timer(interval*1000), last_frame(-1), time_format(SEC), debug(debug), log_file(), csv_sep(), dec_sep(), neg_sign(), ssocr()
3333
{
3434
if (interval<0)
3535
env->ThrowError("SegmentDisplayOCR: interval can't be negative number!");
@@ -95,13 +95,22 @@ OCRFilter::~OCRFilter()
9595
log_file.close();
9696
}
9797

98+
//Rounding algorithm from Java 7
99+
int OCRFilter::Round(double num)
100+
{
101+
if (num!=0.49999999999999994)
102+
return (int)floor(num+0.5);
103+
else
104+
return 0;
105+
}
106+
98107
//GetFrame is called only when client or parent filter requests frame
99108
PVideoFrame __stdcall OCRFilter::GetFrame(int n, IScriptEnvironment *env)
100109
{
101110
PVideoFrame src=child->GetFrame(n, env);
102111

103112
//For the sake of optimization, following variables are computed only ones per iteration
104-
unsigned int cur_mseconds=fduration*n;
113+
unsigned int cur_mseconds=Round(fduration*n);
105114
bool newer=IsNewer(n);
106115
bool alarm=CheckTimer(cur_mseconds);
107116
std::string timestamp=(debug||(time_format==TMS&&alarm))?GetTimestamp(cur_mseconds):"";
@@ -165,7 +174,7 @@ bool OCRFilter::CheckTimer(unsigned int cur_mseconds)
165174
return true;
166175

167176
unsigned int last_alarm=cur_mseconds-cur_mseconds%timer;
168-
if (cur_mseconds>=last_alarm&&cur_mseconds<(last_alarm+fduration))
177+
if (cur_mseconds>=last_alarm&&cur_mseconds<(last_alarm+Round(fduration)))
169178
return true;
170179
else
171180
return false;

src/ocrf.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
class OCRFilter: public GenericVideoFilter {
2222
private:
2323
enum TFEnum {TMS, RTM, SEC, MSEC, FRAME};
24-
unsigned int fduration; //Frame duration in mseconds
24+
double fduration; //Frame duration in mseconds
2525
unsigned int timer; //Timer in mseconds
2626
int last_frame; //Last processed frame
2727
TFEnum time_format;
@@ -34,6 +34,7 @@ class OCRFilter: public GenericVideoFilter {
3434
char time_fmt[80];
3535
Ssocr *ssocr;
3636

37+
int Round(double num);
3738
std::string GetTimestamp(unsigned int cur_mseconds);
3839
bool CheckTimer(unsigned int cur_mseconds);
3940
bool IsNewer(int cur_frame);

0 commit comments

Comments
 (0)