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 <fvfilters/or.h>
24
25
#include <core/exception.h>
26
27
#include <cstddef>
28
29
#ifdef HAVE_IPP
30
# include <ippi.h>
31
#elif defined(HAVE_OPENCV)
32
# if CV_MAJOR_VERSION < 2 || (CV_MAJOR_VERSION == 2 && CV_MINOR_VERSION < 4)
33
# include <opencv/cv.h>
34
# endif
35
# include <opencv/cv.hpp>
36
#else
37
# error "Neither IPP nor OpenCV available"
38
#endif
39
40
namespace
firevision
{
41
#if 0
/* just to make Emacs auto-indent happy */
42
}
43
#endif
44
45
/** @class FilterOr <fvfilters/or.h>
46
* Or filter.
47
* @author Tim Niemueller
48
*/
49
50
/** Constructor. */
51
FilterOr::FilterOr()
52
:
Filter
(
"FilterOr"
, 2)
53
{
54
}
55
56
57
void
58
FilterOr::apply
()
59
{
60
#ifdef HAVE_IPP
61
IppiSize size;
62
size.width =
src_roi
[0]->
width
;
63
size.height =
src_roi
[0]->
height
;
64
65
IppStatus status;
66
67
if
( (
dst
== NULL) || (
dst
==
src
[1]) ) {
68
// In-place
69
status = ippiOr_8u_C1IR(
src
[0] + (
src_roi
[0]->start.y *
src_roi
[0]->
line_step
) + (
src_roi
[0]->
start
.
x
*
src_roi
[0]->
pixel_step
),
70
src_roi
[0]->
line_step
,
71
src
[1] + (
src_roi
[1]->
start
.
y
*
src_roi
[1]->
line_step
) + (
src_roi
[1]->
start
.
x
*
src_roi
[1]->
pixel_step
),
72
src_roi
[1]->
line_step
,
73
size);
74
75
}
else
{
76
status = ippiOr_8u_C1R(
src
[0] + (
src_roi
[0]->start.y *
src_roi
[0]->
line_step
) + (
src_roi
[0]->
start
.
x
*
src_roi
[0]->
pixel_step
),
77
src_roi
[0]->
line_step
,
78
src
[1] + (
src_roi
[1]->
start
.
y
*
src_roi
[1]->
line_step
) + (
src_roi
[1]->
start
.
x
*
src_roi
[1]->
pixel_step
),
79
src_roi
[1]->
line_step
,
80
dst
+ (
dst_roi
->
start
.
y
*
dst_roi
->
line_step
) + (
dst_roi
->
start
.
x
*
dst_roi
->
pixel_step
),
81
dst_roi
->
line_step
,
82
size);
83
}
84
85
if
( status != ippStsNoErr ) {
86
throw
fawkes::Exception
(
"Or filter failed with %i\n"
, status);
87
}
88
#elif defined(HAVE_OPENCV)
89
90
if
((
dst
== NULL) || (
dst
==
src
[0])) {
91
throw
fawkes::Exception
(
"OpenCV-based OR filter cannot be in-place"
);
92
}
93
94
cv::Mat srcm_0(
src_roi
[0]->height,
src_roi
[0]->width, CV_8UC1,
95
src
[0] +
96
(
src_roi
[0]->start.y *
src_roi
[0]->
line_step
) +
97
(
src_roi
[0]->
start
.
x
*
src_roi
[0]->
pixel_step
),
98
src_roi
[0]->
line_step
);
99
100
cv::Mat srcm_1(
src_roi
[1]->height,
src_roi
[1]->width, CV_8UC1,
101
src
[1] +
102
(
src_roi
[1]->start.y *
src_roi
[1]->
line_step
) +
103
(
src_roi
[1]->
start
.
x
*
src_roi
[1]->
pixel_step
),
104
src_roi
[1]->
line_step
);
105
106
cv::Mat dstm(
dst_roi
->
height
,
dst_roi
->
width
, CV_8UC1,
107
dst
+
108
(
dst_roi
->
start
.
y
*
dst_roi
->
line_step
) +
109
(
dst_roi
->
start
.
x
*
dst_roi
->
pixel_step
),
110
dst_roi
->
line_step
);
111
112
cv::bitwise_or(srcm_0, srcm_1, dstm);
113
114
#endif
115
}
116
117
}
// end namespace firevision
firevision::FilterOr::apply
virtual void apply()
Apply the filter.
Definition:
or.cpp:58
firevision::ROI::start
fawkes::upoint_t start
ROI start.
Definition:
roi.h:119
fawkes::upoint_t::y
unsigned int y
y coordinate
Definition:
types.h:36
fawkes::upoint_t::x
unsigned int x
x coordinate
Definition:
types.h:35
firevision::ROI::width
unsigned int width
ROI width.
Definition:
roi.h:121
firevision
Definition:
vision_master.h:32
firevision::Filter::src
unsigned char ** src
Source buffers, dynamically allocated by Filter ctor.
Definition:
filter.h:65
fawkes::Exception
Base class for exceptions in Fawkes.
Definition:
exception.h:36
firevision::Filter
Filter interface.
Definition:
filter.h:35
firevision::Filter::src_roi
ROI ** src_roi
Source ROIs, dynamically allocated by Filter ctor.
Definition:
filter.h:70
firevision::ROI::height
unsigned int height
ROI height.
Definition:
roi.h:123
firevision::ROI::line_step
unsigned int line_step
line step
Definition:
roi.h:129
firevision::Filter::dst
unsigned char * dst
Destination buffer.
Definition:
filter.h:67
firevision::ROI::pixel_step
unsigned int pixel_step
pixel step
Definition:
roi.h:131
firevision::Filter::dst_roi
ROI * dst_roi
Destination ROI.
Definition:
filter.h:72
src
libs
fvfilters
or.cpp
Generated by
1.8.14