52 std::unique_lock lock(imageMutex);
57 cameraImages =
new CByteImage*[2];
78 std::unique_lock lock(imageMutex);
82 ARMARX_WARNING <<
"Timeout while waiting for camera images (>1000ms)";
95 IplImage* ppIplImages[1] = {IplImageAdaptor::Adapt(cameraImages[0])};
97 cv::Mat image = cv::cvarrToMat(ppIplImages[0]);
100 cv::cvtColor(image, gray_image, cv::COLOR_BGR2GRAY);
102 double blurrinessLaplaceVariance = laplaceVarianceBlurrinessMetric(gray_image);
103 double blurrinessPerceptualBlur = blurringPerceptual(gray_image);
104 double blurrinessMarziliano = blurringMarziliano(gray_image);
107 << ((blurrinessLaplaceVariance < thresholdLaplace) ?
"Blurry" :
"Not blurry")
108 <<
" Value: " << blurrinessLaplaceVariance;
110 << ((blurrinessPerceptualBlur > thresholdPerceptual) ?
"Blurry" :
"Not blurry")
111 <<
" Value: " << blurrinessPerceptualBlur;
115 debugValues[
"BlurrinessValueLaplace"] =
new Variant(blurrinessLaplaceVariance);
116 debugValues[
"BlurryLaplace"] =
new Variant((blurrinessLaplaceVariance < thresholdLaplace));
118 debugValues[
"BlurrinessValuePerceptual"] =
new Variant(blurrinessPerceptualBlur);
119 debugValues[
"BlurryPerceptual"] =
new Variant((blurrinessPerceptualBlur > thresholdPerceptual));
121 debugValues[
"BlurrinessValueMarziliano"] =
new Variant(blurrinessMarziliano);
123 debugValues[
"seq"] =
new Variant((
int)seq);
126 debugObserver->setDebugChannel(
"BlurrinessMetric", debugValues);
128 CByteImage* resultImages[1] = {IplImageAdaptor::Adapt(ppIplImages[0])};
133 fpsCounter.assureFPS(frameRate);
145armarx::BlurrinessMetric::laplaceVarianceBlurrinessMetric(cv::Mat& in)
148 cv::Laplacian(in, out, CV_64F);
150 cv::Scalar
mean, variance;
151 cv::meanStdDev(out,
mean, variance);
153 return (variance.val[0] * variance.val[0]);
170armarx::BlurrinessMetric::blurringPerceptual(
const cv::Mat& src)
172 double blur_index = 0;
174 cv::Mat smoothV(src.rows, src.cols, CV_8UC1);
175 cv::Mat smoothH(src.rows, src.cols, CV_8UC1);
176 cv::blur(src, smoothV, cv::Size(1, 9));
177 cv::blur(src, smoothH, cv::Size(9, 1));
180 double difS_V = 0, difS_H = 0, difB_V = 0, difB_H = 0;
181 double somaV = 0, somaH = 0, varV = 0, varH = 0;
183 for (
int i = 0; i < src.rows; ++i)
186 for (
int j = 0; j < src.cols; ++j)
191 difS_V =
abs(src.at<uchar>(i, j) - src.at<uchar>(i - 1, j));
192 difB_V =
abs(smoothV.at<uchar>(i, j) - smoothV.at<uchar>(i - 1, j));
197 difS_H =
abs(src.at<uchar>(i, j) - src.at<uchar>(i, j - 1));
198 difB_H =
abs(smoothH.at<uchar>(i, j) - smoothH.at<uchar>(i, j - 1));
201 varV += cv::max(0.0, difS_V - difB_V);
202 varH += cv::max(0.0, difS_H - difB_H);
208 blur_index = cv::max((somaV - varV) / somaV, (somaH - varH) / somaH);
225armarx::BlurrinessMetric::blurringMarziliano(
const cv::Mat& src)
227 double blur_index = 0;
229 cv::Mat edges(src.rows, src.cols, CV_8UC1);
230 cv::Mat element = cv::getStructuringElement(cv::MORPH_RECT, cv::Size(3, 3));
232 cv::GaussianBlur(src, edges, cv::Size(3, 3), 0);
233 cv::morphologyEx(edges, edges, cv::MORPH_OPEN, element);
234 cv::morphologyEx(edges, edges, cv::MORPH_CLOSE, element);
235 cv::Sobel(edges, edges, CV_8UC1, 1, 0);
237 unsigned int edge_counter = 0;
247 for (
int i = 0; i < src.rows; ++i)
249 for (
int j = 0; j < src.cols; ++j)
255 if (edges.at<uchar>(i, j) > 0)
267 if ((src.at<uchar>(i, j - 1) - src.at<uchar>(i, j)) > 0)
270 max = src.at<uchar>(i, k);
271 while ((
max <= src.at<uchar>(i, k - 1)) && (k > 1))
274 max = src.at<uchar>(i, k);
281 min = src.at<uchar>(i, k);
282 while ((
min >= src.at<uchar>(i, k - 1)) && (k > 1))
285 min = src.at<uchar>(i, k);
292 if (j == (src.cols - 1))
294 c_end = src.cols - 1;
299 if ((src.at<uchar>(i, j + 1) - src.at<uchar>(i, j)) > 0)
302 max = src.at<uchar>(i, k);
303 while (
max <= src.at<uchar>(i, k + 1))
306 max = src.at<uchar>(i, k);
308 if (k == src.cols - 1)
317 min = src.at<uchar>(i, k);
318 while (
min >= src.at<uchar>(i, k + 1))
321 min = src.at<uchar>(i, k);
323 if (k == src.cols - 1)
331 assert((c_end - c_start) >= 0);
332 length += (c_end - c_start);
338 if (edge_counter != 0)
340 blur_index = ((double)length) / edge_counter;
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
SpamFilterDataPtr deactivateSpam(SpamFilterDataPtr const &spamFilter, float deactivationDurationSec, const std::string &identifier, bool deactivate)
Brief description of class BlurrinessMetric.
void onConnectImageProcessor() override
Implement this method in the ImageProcessor in order execute parts when the component is fully initia...
void onExitImageProcessor() override
Exit the ImapeProcessor component.
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void process() override
Process the vision component.
void onInitImageProcessor() override
Setup the vision component.
static std::string GetDefaultName()
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Property< PropertyType > getProperty(const std::string &name)
void offeringTopic(const std::string &name)
Registers a topic for retrival after initialization.
TopicProxyType getTopic(const std::string &name)
Returns a proxy of the specified topic.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
The Variant class is described here: Variants.
void usingImageProvider(std::string name)
Registers a delayed topic subscription and a delayed provider proxy retrieval which all will be avail...
bool waitForImages(int milliseconds=1000)
Wait for new images.
ImageProviderInfo getImageProvider(std::string name, ImageType destinationImageType=eRgb, bool waitForProxy=false)
Select an ImageProvider.
int getImages(CByteImage **ppImages)
Poll images from provider.
void provideResultImages(CByteImage **images, armarx::MetaInfoSizeBasePtr info=nullptr)
sends result images for visualization
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::optional< float > mean(const boost::circular_buffer< NameValueMap > &buffer, const std::string &key)
std::map< std::string, VariantBasePtr > StringVariantBaseMap
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
std::vector< T > max(const std::vector< T > &v1, const std::vector< T > &v2)
std::vector< T > abs(const std::vector< T > &v)
std::vector< T > min(const std::vector< T > &v1, const std::vector< T > &v2)