void create_masksub_chunks(IFFByteStream &iff, const GURL &url) { // Check and load pixmap file if (!g().stencil) G_THROW("The use of a raw ppm image requires a stencil"); GP<ByteStream> gibs=ByteStream::create(url, "rb"); ByteStream &ibs=*gibs; GP<GPixmap> graw_pm=GPixmap::create(ibs); GPixmap &raw_pm=*graw_pm; if ((int) g().stencil->get_width() != (int) raw_pm.columns()) G_THROW("Stencil and raw image have different widths!"); if ((int) g().stencil->get_height() != (int) raw_pm.rows()) G_THROW("Stencil and raw image have different heights!"); // Encode foreground { GP<GPixmap> gfg_img=GPixmap::create(); GPixmap &fg_img=*gfg_img; GP<GBitmap> fg_mask=GBitmap::create(); processForeground(&raw_pm, g().stencil, fg_img, *fg_mask); GP<IW44Image> fg_pm = IW44Image::create_encode(fg_img, fg_mask, IW44Image::CRCBfull); IWEncoderParms parms[8]; iff.put_chunk("FG44"); parms[0].slices = 100; fg_pm->encode_chunk(iff.get_bytestream(), parms[0]); iff.close_chunk(); } // Encode backgound { GP<GPixmap> gbg_img=GPixmap::create(); GPixmap &bg_img=*gbg_img; GP<GBitmap> bg_mask=GBitmap::create(); processBackground(&raw_pm, g().stencil, bg_img, *bg_mask); GP<IW44Image> bg_pm = IW44Image::create_encode(bg_img, bg_mask, IW44Image::CRCBnormal); IWEncoderParms parms[4]; parms[0].bytes = 10000; parms[0].slices = 74; iff.put_chunk("BG44"); bg_pm->encode_chunk(iff.get_bytestream(), parms[0]); iff.close_chunk(); parms[1].slices = 84; iff.put_chunk("BG44"); bg_pm->encode_chunk(iff.get_bytestream(), parms[1]); iff.close_chunk(); parms[2].slices = 90; iff.put_chunk("BG44"); bg_pm->encode_chunk(iff.get_bytestream(), parms[2]); iff.close_chunk(); parms[3].slices = 97; iff.put_chunk("BG44"); bg_pm->encode_chunk(iff.get_bytestream(), parms[3]); iff.close_chunk(); } }
bool RTHumidityHTU21D::humidityRead(RTIMU_DATA& data) { if (!processBackground()) return false; data.humidityValid = m_humidityValid; data.humidity = m_humidity; data.temperatureValid = m_temperatureValid; data.temperature = m_temperature; return true; }
bool WindowDetector::processColor(Image* input, Image* output, ColorFilter& filter, BlobDetector::Blob& outerBlob, BlobDetector::Blob& innerBlob) { tempFrame->copyFrom(input); tempFrame->setPixelFormat(Image::PF_RGB_8); tempFrame->setPixelFormat(Image::PF_LCHUV_8); filter.filterImage(tempFrame, output); // Erode the image (only if necessary) IplImage* img = output->asIplImage(); if (m_erodeIterations > 0) { cvErode(img, img, NULL, m_erodeIterations); } // Dilate the image (only if necessary) if (m_dilateIterations > 0) { cvDilate(img, img, NULL, m_dilateIterations); } m_blobDetector.processImage(output); BlobDetector::BlobList blobs = m_blobDetector.getBlobs(); BOOST_FOREACH(BlobDetector::Blob blob, blobs) { // Sanity check blob double pixelPercentage = blob.getSize() / (double) (blob.getHeight() * blob.getWidth()); double aspect = blob.getTrueAspectRatio(); if (aspect <= m_maxAspectRatio && aspect >= m_minAspectRatio && m_minHeight <= blob.getHeight() && m_minWidth <= blob.getWidth() && m_minPixelPercentage <= pixelPercentage && m_maxPixelPercentage >= pixelPercentage && processBackground(tempFrame, filter, blob, innerBlob)) { int outerCenterX = (blob.getMaxX() - blob.getMinX()) / 2 + blob.getMinX(); int innerCenterX = (innerBlob.getMaxX() - innerBlob.getMinX()) / 2 + innerBlob.getMinX(); int outerCenterY = (blob.getMaxY() - blob.getMinY()) / 2 + blob.getMinY(); int innerCenterY = (innerBlob.getMaxY() - innerBlob.getMinY()) / 2 + innerBlob.getMinY(); int centerXdiff = abs(outerCenterX - innerCenterX); int centerYdiff = abs(outerCenterY - innerCenterY); double relHeight = (double) innerBlob.getHeight() / blob.getHeight(); double relWidth = (double) innerBlob.getWidth() / blob.getWidth(); if(centerXdiff < m_centerXDisagreement && centerYdiff < m_centerYDisagreement && relHeight > m_minRelInnerHeight && relWidth > m_minRelInnerWidth) { outerBlob = blob; return true; } } }