Fawkes API
Fawkes Development Version
or.cpp
1
2
/***************************************************************************
3
* or.cpp - Implementation for "or'ing" images together
4
*
5
* Created: Fri May 13 14:57:10 2005
6
* Copyright 2005-2012 Tim Niemueller [www.niemueller.de]
7
****************************************************************************/
8
9
/* This program is free software; you can redistribute it and/or modify
10
* it under the terms of the GNU General Public License as published by
11
* the Free Software Foundation; either version 2 of the License, or
12
* (at your option) any later version. A runtime exception applies to
13
* this software (see LICENSE.GPL_WRE file mentioned below for details).
14
*
15
* This program is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU Library General Public License for more details.
19
*
20
* Read the full text in the LICENSE.GPL_WRE file in the doc directory.
21
*/
22
23
#include <core/exception.h>
24
#include <fvfilters/or.h>
25
26
#include <cstddef>
27
28
#ifdef HAVE_IPP
29
# include <ippi.h>
30
#elif defined(HAVE_OPENCV)
31
# include <opencv2/opencv.hpp>
32
#else
33
# error "Neither IPP nor OpenCV available"
34
#endif
35
36
namespace
firevision {
37
38
/** @class FilterOr <fvfilters/or.h>
39
* Or filter.
40
* @author Tim Niemueller
41
*/
42
43
/** Constructor. */
44
FilterOr::FilterOr
() :
Filter
(
"FilterOr"
, 2)
45
{
46
}
47
48
void
49
FilterOr::apply
()
50
{
51
#ifdef HAVE_IPP
52
IppiSize size;
53
size.width =
src_roi
[0]->
width
;
54
size.height =
src_roi
[0]->
height
;
55
56
IppStatus status;
57
58
if
((
dst
== NULL) || (
dst
==
src
[1])) {
59
// In-place
60
status = ippiOr_8u_C1IR(
src
[0] + (
src_roi
[0]->start.y *
src_roi
[0]->
line_step
)
61
+ (
src_roi
[0]->
start
.
x
*
src_roi
[0]->
pixel_step
),
62
src_roi
[0]->
line_step
,
63
src
[1] + (
src_roi
[1]->
start
.
y
*
src_roi
[1]->
line_step
)
64
+ (
src_roi
[1]->
start
.
x
*
src_roi
[1]->
pixel_step
),
65
src_roi
[1]->
line_step
,
66
size);
67
68
}
else
{
69
status = ippiOr_8u_C1R(
src
[0] + (
src_roi
[0]->start.y *
src_roi
[0]->
line_step
)
70
+ (
src_roi
[0]->
start
.
x
*
src_roi
[0]->
pixel_step
),
71
src_roi
[0]->
line_step
,
72
src
[1] + (
src_roi
[1]->
start
.
y
*
src_roi
[1]->
line_step
)
73
+ (
src_roi
[1]->
start
.
x
*
src_roi
[1]->
pixel_step
),
74
src_roi
[1]->
line_step
,
75
dst
+ (
dst_roi
->
start
.
y
*
dst_roi
->
line_step
)
76
+ (
dst_roi
->
start
.
x
*
dst_roi
->
pixel_step
),
77
dst_roi
->
line_step
,
78
size);
79
}
80
81
if
(status != ippStsNoErr) {
82
throw
fawkes::Exception
(
"Or filter failed with %i\n"
, status);
83
}
84
#elif defined(HAVE_OPENCV)
85
86
if
((
dst
== NULL) || (
dst
==
src
[0])) {
87
throw
fawkes::Exception
(
"OpenCV-based OR filter cannot be in-place"
);
88
}
89
90
cv::Mat srcm_0(
src_roi
[0]->height,
91
src_roi
[0]->width,
92
CV_8UC1,
93
src
[0] + (
src_roi
[0]->start.y *
src_roi
[0]->
line_step
)
94
+ (
src_roi
[0]->
start
.
x
*
src_roi
[0]->
pixel_step
),
95
src_roi
[0]->
line_step
);
96
97
cv::Mat srcm_1(
src_roi
[1]->height,
98
src_roi
[1]->width,
99
CV_8UC1,
100
src
[1] + (
src_roi
[1]->start.y *
src_roi
[1]->
line_step
)
101
+ (
src_roi
[1]->
start
.
x
*
src_roi
[1]->
pixel_step
),
102
src_roi
[1]->
line_step
);
103
104
cv::Mat dstm(
dst_roi
->
height
,
105
dst_roi
->
width
,
106
CV_8UC1,
107
dst
+ (
dst_roi
->
start
.
y
*
dst_roi
->
line_step
)
108
+ (
dst_roi
->
start
.
x
*
dst_roi
->
pixel_step
),
109
dst_roi
->
line_step
);
110
111
cv::bitwise_or(srcm_0, srcm_1, dstm);
112
113
#endif
114
}
115
116
}
// end namespace firevision
fawkes::Exception
Base class for exceptions in Fawkes.
Definition:
exception.h:36
firevision::FilterOr::apply
virtual void apply()
Apply the filter.
Definition:
or.cpp:49
firevision::FilterOr::FilterOr
FilterOr()
Constructor.
Definition:
or.cpp:44
firevision::Filter
Filter interface.
Definition:
filter.h:33
firevision::Filter::src_roi
ROI ** src_roi
Source ROIs, dynamically allocated by Filter ctor.
Definition:
filter.h:66
firevision::Filter::src
unsigned char ** src
Source buffers, dynamically allocated by Filter ctor.
Definition:
filter.h:61
firevision::Filter::dst
unsigned char * dst
Destination buffer.
Definition:
filter.h:63
firevision::Filter::dst_roi
ROI * dst_roi
Destination ROI.
Definition:
filter.h:68
firevision::ROI::height
unsigned int height
ROI height.
Definition:
roi.h:119
firevision::ROI::start
fawkes::upoint_t start
ROI start.
Definition:
roi.h:115
firevision::ROI::line_step
unsigned int line_step
line step
Definition:
roi.h:125
firevision::ROI::width
unsigned int width
ROI width.
Definition:
roi.h:117
firevision::ROI::pixel_step
unsigned int pixel_step
pixel step
Definition:
roi.h:127
fawkes::upoint_t::x
unsigned int x
x coordinate
Definition:
types.h:36
fawkes::upoint_t::y
unsigned int y
y coordinate
Definition:
types.h:37
src
libs
fvfilters
or.cpp
Generated by
1.9.4