Esempio n. 1
0
DirectShowCaptureInterface::~DirectShowCaptureInterface()
{
    if (isRunning)
    {
        /*
            Callback is set safe and synchroniously,
            so after the call of the callback reset, we will never again
            receive a frame. So it will be safe to destroy the object
        */
        for (int i = 0; i < Frames::MAX_INPUTS_NUMBER; i++)
        {
            if (isCorrectDeviceHandle(i))
            {
                DirectShowCapDll_stop(mCameras[i].deviceHandle);
            }
        }
        isRunning = false;
    }

    for (int i = 0; i < Frames::MAX_INPUTS_NUMBER; i++)
    {
        if (isCorrectDeviceHandle(i))
        {
            delete_safe(mCameras[i].buffer);
            delete_safe(mCameras[i].buffer24);

            DirectShowCapDll_setFrameCallback(mCameras[i].deviceHandle, NULL, NULL);
            DirectShowCapDll_deinit(mCameras[i].deviceHandle);
            mCameras[i].deviceHandle = -1;
        }
    }
}
Esempio n. 2
0
AdvancedImageWidget::~AdvancedImageWidget()
{
    delete_safe(mUi);
    delete_safe(mSaveDialog);
    delete_safe(mResizeCache);

   // qDebug("AdvancedImageWidget::~AdvancedImageWidget(%p): called", this);
}
BufferFactory::~BufferFactory()
{
    // delete all registered loaders
    vector<BufferLoader<G12Buffer> *>::iterator it;
    for (it = mLoadersG12.begin(); it != mLoadersG12.end(); it++)
    {
        delete_safe (*it);
    }
    mLoadersG12.clear();
    //printf("BufferFactory has been destroyed.\n");
}
Esempio n. 4
0
void RGB24Buffer::drawIsolines(
        double zx, double zy,
        double zh, double zw,
        double steps,
        FunctionArgs &f)
{
   int i,j;
   if (f.inputs < 2)
       return;

   AbstractBuffer<double> *values = new AbstractBuffer<double>(this->getSize());

   double *in =  new double[f.inputs ];
   double *out = new double[f.outputs];
   for (int i = 0; i < f.inputs; i++) {
       in[i] = 0.0;
   }

   for (i = 0; i < h; i++)
   {
       for (j = 0; j < w; j++)
       {
           in[0] = (i * zh / h)  + zy;
           in[1] = (j * zw / w)  + zx;
           f(in, out);
           values->element(i,j) = out[0];
          /* if (j == w / 2) {
               printf("out: [%d %d] %lf\n", i, j, out[0]);
           }*/
       }
   }

   for (i = 1; i < h - 1; i++)
   {
       for (j = 1; j < w - 1; j++)
       {
           double c = values->element(i,j);
           double r = values->element(i,j + 1);
           double l = values->element(i + 1,j);

           double ls = ((int) (c * steps)) / steps;
           double hs = ((int) (c * steps) + 1) / steps;
           if (r < ls || r > hs ||
               l < ls || l > hs )
               element(i,j) = RGBColor::gray(128);
       }
   }

   deletearr_safe(in);
   deletearr_safe(out);
   delete_safe(values);
}
Esempio n. 5
0
FileCaptureInterface::FramePair FileCaptureInterface::getFrame()
{
    FramePair result;

    string name0 = getImageFileName(mCount, 0);
    string name1 = getImageFileName(mCount, 1);

    if (mVerbose) {
        printf("Grabbing frame from file: %s\n", name0.c_str());
    }

    result.bufferLeft = BufferFactory::getInstance()->loadG12Bitmap(name0);

    if (result.bufferLeft)
    {
        if (mVerbose) {
            printf("Grabbing frame from file: %s\n", name1.c_str());
        }

        result.bufferRight = BufferFactory::getInstance()->loadG12Bitmap(name1);
    }

    if (!result.bufferLeft || !result.bufferRight)
    {
        delete_safe(result.bufferLeft);
        delete_safe(result.bufferRight);

        if (mVerbose) {
            printf("File not found, resetting to first image in the sequence.\n");
        }

        resetImageFileCounter();
        return getFrame();
    }

    increaseImageFileCounter();
    return result;
}
Esempio n. 6
0
void MainWindow::onDisconnected()
{
    qDebug() << "Disconnected!";

    delete_safe(_socket);

   _isConnected = false;

   for (TemperatureIndicator* currentTemperatureIndicator: _temperatureIndicators) {
       currentTemperatureIndicator->setSensorError(SensorError::Undefined);
   }

   connectSocket();
} // onDisconnected
Esempio n. 7
0
int main (int argc, char **argv)
{
	QCoreApplication app(argc, argv);
	printf("Attempting a grab\n");
	V4L2CaptureInterface *input = static_cast<V4L2CaptureInterface*>(ImageCaptureInterface::fabric("v4l2:/dev/video0,/dev/video1"));
	input->initCapture();
	input->startCapture();

	RGB24Buffer *result = NULL;

	for(int i = 0; i < 40; i++) {
	    delete_safe(result);
	    V4L2CaptureInterface::FramePair pair = input->getFrameRGB24();
	    result = pair.rgbBufferLeft;
	    delete_safe(pair.bufferRight);
	    delete_safe(pair.bufferLeft);
        delete_safe(pair.rgbBufferRight);
	}

	BMPLoader().save("snapshot.bmp", result);
	delete_safe(result);
	return 0;
}
void SelectableGeometryFeatures::deleteVertex(Vertex *vertex)
{
    VertexPath *ownerPath = vertex->ownerPath;

    removeSelection(vertex);

    if (ownerPath != NULL) {
        removeVertexFromPath(vertex);
    }

    vector<Vertex *>::iterator it = std::remove(mPoints.begin(), mPoints.end(), vertex);
    mPoints.erase(it, mPoints.end());
    delete_safe (vertex);
}
Esempio n. 9
0
void AdvancedImageWidget::recomputeRects()
{
    if (mImage == NULL)
    {
       return;
    }

    QRect output (mImage->rect());
    if (!isRotationLandscape()) {
        output.setWidth (mImage->height());
        output.setHeight(mImage->width ());
    }

    output = output.normalized();
    QRect input = computeInputRect();

    if (mUi->fitToWindowCheckBox->isChecked())
    {
        output = mUi->widget->rect().normalized();

        if (mUi->aspectCheckBox->isChecked())
        {
            double inputAspect = 1.0;
            if (isRotationLandscape()) {
                inputAspect = (double)input.height() / input.width();
            } else {
                inputAspect = (double)input.width() / input.height();
            }

            int outH = output.width() * inputAspect;
            if (outH > output.height())
                output.setWidth(output.height() / inputAspect);
            else
                output.setHeight(output.width() * inputAspect);
        }
    }

    if (!output.isValid())
        output = QRect(0,0,1,1);

    mOutputRect = output;
    mInputRect  = input;
    delete_safe(mResizeCache), mResizeCache = NULL;
}
Esempio n. 10
0
void AdvancedImageWidget::setImage(QSharedPointer<QImage> newImage)
{
    if (mIsFreezed)
        return;

    /*if (newImage.isNull())
        return;*/

    mImage = newImage;

    delete_safe(mResizeCache);

    if (mSaveProcStarted)
    {
        mResizeCache = new QImage(mOutputRect.size(), QImage::Format_RGB32);
        mResizeCache->fill(0);
        QPainter cachePainter(mResizeCache);
        drawResized(cachePainter);
        cachePainter.setPen(QColor(Qt::red));
        cachePainter.drawRect(mResizeCache->rect().adjusted(0,0,-1,-1));

        cachePainter.end();
        saveFlowImage(mResizeCache);
    }

    if ((!mImage.isNull() && mImageSize != mImage->size()) || (mZoomCenter == QPoint(-1,-1)))
    {
        if (mImage.isNull()) {
            mImageSize = QSize();
        } else {
            mImageSize = mImage->size();
        }
        recalculateZoomCenter();
    }
    recomputeRects();
    forceUpdate();
}
Esempio n. 11
0
ALIGN_STACK_SSE void DirectShowCaptureInterface::memberCallback(DSCapDeviceId dev, FrameData data)
{
    //SYNC_PRINT(("Received new frame in a member %d\n", dev));
    mProtectFrame.lock();

    DirectShowCameraDescriptor *camera = NULL;
    if (mCameras[0].deviceHandle == dev) camera = &mCameras[0];
    else
    if (mCameras[1].deviceHandle == dev) camera = &mCameras[1];
    else
        goto exit;

    {
        PreciseTimer timer = PreciseTimer::currentTime();
        camera->gotBuffer = true;
        camera->timestamp = (data.timestamp + 5) / 10;
        delete_safe (camera->buffer);
        delete_safe (camera->buffer24);

        if (data.format.type == CAP_YUV)
        {
            if (mIsRgb) {
                camera->buffer24 = new RGB24Buffer(data.format.height, data.format.width, false);
                camera->buffer24->fillWithYUYV((uint8_t *)data.data);
            }
            else {
                camera->buffer = new G12Buffer(data.format.height, data.format.width, false);
                camera->buffer->fillWithYUYV((uint16_t *)data.data);
            }
        }
        else if (data.format.type == CAP_MJPEG)
        {
            MjpegDecoderLazy *lazyDecoder = new MjpegDecoderLazy;   // don't place it at stack, it's too huge!
            if (mIsRgb)
                camera->buffer24 = lazyDecoder->decodeRGB24((uchar *)data.data);
            else
                camera->buffer   = lazyDecoder->decode((uchar *)data.data);
            delete lazyDecoder;
        }
        else if (data.format.type == CAP_RGB)
        {
            if (mIsRgb) {
                camera->buffer24 = new RGB24Buffer(data.format.height, data.format.width, true);
                int w = camera->buffer24->w;
                int h = camera->buffer24->h;
                for (int i = 0; i < h; i++) {
                    uint8_t  *rgbData = ((uint8_t *)data.data) + 3 * (h - i - 1) * w;
                    RGBColor *rgb24Data = &(camera->buffer24->element(i, 0));
                    for (int j = 0; j < w; j++) {
                        RGBColor rgb(rgbData[2], rgbData[1], rgbData[0]);   // the given data format has B,G,R order
                        *rgb24Data++ = rgb;
                        rgbData += 3;
                    }
                }
            }
            else {
                camera->buffer = new G12Buffer(data.format.height, data.format.width, false);
                int w = camera->buffer->w;
                int h = camera->buffer->h;
                for (int i = 0; i < h; i++) {
                    uint8_t  *rgbData = ((uint8_t *)data.data) + 3 * (h - i - 1) * w;
                    uint16_t *greyData = &(camera->buffer->element(i, 0));
                    for (int j = 0; j < w; j++) {
                        RGBColor rgb(rgbData[2], rgbData[1], rgbData[0]);   // the given data format has B,G,R order
                        *greyData++ = rgb.luma12();
                        rgbData += 3;
                    }
                }
            }
        }
        else {
            camera->buffer = new G12Buffer(data.format.height, data.format.width, false);
        }

        camera->decodeTime = timer.usecsToNow();
        /* If both frames are in place */

        if (mCameras[0].gotBuffer && mCameras[1].gotBuffer)
        {
            mCameras[0].gotBuffer = false;
            mCameras[1].gotBuffer = false;

            CaptureStatistics stats;
            int64_t desync = mCameras[0].timestamp - mCameras[1].timestamp;
            stats.values[CaptureStatistics::DESYNC_TIME] = desync > 0 ? desync : -desync;
            stats.values[CaptureStatistics::DECODING_TIME] = mCameras[0].decodeTime + mCameras[1].decodeTime;
            if (lastFrameTime.usecsTo(PreciseTimer()) != 0)
            {
                stats.values[CaptureStatistics::INTERFRAME_DELAY] = lastFrameTime.usecsToNow();
            }
            lastFrameTime = PreciseTimer::currentTime();

            frame_data_t frameData;
            frameData.timestamp = mCameras[0].timestamp / 2 + mCameras[1].timestamp / 2;
            newFrameReady(frameData);
            newStatisticsReady(stats);
        }
        else {
            frame_data_t frameData;
            frameData.timestamp = mCameras[0].timestamp;
            newFrameReady(frameData);
            //newStatisticsReady(stats);
            skippedCount++;
        }
    }
exit:
    mProtectFrame.unlock();
}
Esempio n. 12
0
void Clustering3D::_clustering(int sizeW, int sizeH)
{
    mMarkup = new AbstractBuffer<CloudCluster *>(sizeH, sizeW);
    mpClusters.clear();

    int y = 0;
    int x = 0;
    int k = 0;
    int r = 0;
    bool addingPending;

    for(unsigned i = 0; i < mCloud->size(); i++)
    {
        k = (*mCloud)[i].texCoor.y();
        r = (*mCloud)[i].texCoor.x();

        addingPending = true;

        for (int j = 0; j < 100; j++)
        {
            if ((int)i - j < 0)
                continue;

            if ( (*mCloud)[i].distTo((*mCloud)[i-j]) > mRadius )
                continue;

            y = (*mCloud)[i - j].texCoor.y();
            x = (*mCloud)[i - j].texCoor.x();

            if (mMarkup->element(y, x) == NULL)
                continue;

            if (addingPending)
            {
                mMarkup->element(y,x)->push_back((*mCloud)[i]);
                mMarkup->element(k,r) = mMarkup->element(y,x);
                addingPending = false;
            }
            else
            {
                mMarkup->element(k,r)->markMerge(mMarkup->element(y,x));
            }
        }

        if (addingPending)
        {
            CloudCluster *newSegment = new CloudCluster();
            newSegment->push_back((*mCloud)[i]);
            mMarkup->element(k,r) = newSegment;
            mpClusters.push_back(newSegment);
        }
     }

    /*Cycle finished. Now we will need to merge segments and delete segments that are not of the need */
    for (unsigned i = 0; i < mpClusters.size(); i++)
    {
        if ( mpClusters[i] != NULL)
            mpClusters[i]->dadify();
    }

    for(unsigned i = 0; i < mCloud->size(); i++)
    {
        int y = (*mCloud)[i].texCoor.y();
        int x = (*mCloud)[i].texCoor.x();
        if (!mMarkup->element(y,x)->isTop())
        {
            mMarkup->element(y,x)->getTopFather()->push_back((*mCloud)[i]);
        }
    }

    for (unsigned i = 0; i < mpClusters.size(); i++)
    {
        if ( !mpClusters[i]->isTop())
            delete_safe(mpClusters[i]);
    }

    /*Delete NULL entries in the vector and shorten the vector*/
    mpClusters.erase(
            remove_if(
                    mpClusters.begin(),
                    mpClusters.end(),
                    bind2nd(equal_to<void *>(), (void *)NULL)
            ),
            mpClusters.end());
    return;
}
Esempio n. 13
0
void Clustering3D::clustering(int sizeW, int sizeH, int zoneW, int zoneH, int zoneDepth)
{
    Cloud *cloudTmp = new Cloud(*mCloud);
    Buffer3d map(sizeW, sizeH, cloudTmp);
    mMarkup = new AbstractBuffer<CloudCluster *>(map.h, map.w);
    mpClusters.clear();

    int dx = zoneW;
    int dy = zoneH;
    int x, y;
    double depth;

    for(int i = 0; i < map.h; i++)
    {
        for(int j = 0; j < map.w; j++)
        {
            if (!map.isElementKnown(i,j))
                continue;

            bool addingPending = true;
            for (int k = -dy; k <= 0; k++)
            {
                for (int l = -dx; l <= dx; l++)
                {

                    if (k == 0 && l == 0)
                        break;

                    x = j + l;
                    y = i + k;

                    if (!map.isValidCoord(y, x))
                        continue;

                    if (mMarkup->element(y,x) == NULL)
                        continue;

                    depth = fabs(map.element(i,j)->point.z() - map.element(y,x)->point.z());
                    if ( depth > zoneDepth )
                        continue;

                    if (addingPending)
                    {
                        mMarkup->element(y,x)->push_back(*(map.element(i,j)));
                        mMarkup->element(i,j) = mMarkup->element(y,x);
                        addingPending = false;
                    }
                    else
                    {
                        mMarkup->element(i,j)->markMerge(mMarkup->element(y,x));
                    }
                }
            }

            if (addingPending)
            {
                CloudCluster *newSegment = new CloudCluster();
                newSegment->push_back(*(map.element(i,j)));
                mMarkup->element(i,j) = newSegment;
                mpClusters.push_back(newSegment);
            }
        }
    }

    /*Cycle finished. Now we will need to merge segments and delete segments that are not of the need */
    vector<CloudCluster *>::iterator it;
    for (it = mpClusters.begin(); it < mpClusters.end(); it++)
    {
        if ( (*it) != NULL)
            (*it)->dadify();
    }

    for(int i = 0; i < map.h; i++)
    {
        for(int j = 0; j < map.w; j++)
        {
            if (mMarkup->element(i,j) == NULL)
                continue;

            if (!mMarkup->element(i,j)->isTop())
            {
                mMarkup->element(i,j)->getTopFather()->push_back(*(map.element(i,j)));
            }
        }
    }

    for (it = mpClusters.begin(); it < mpClusters.end(); it++)
    {
        if ( !(*it)->isTop())
            delete_safe(*it);
    }

    /*Delete NULL entries in the vector and shorten the vector*/
    mpClusters.erase(
            remove_if(
                    mpClusters.begin(),
                    mpClusters.end(),
                    bind2nd(equal_to<void *>(), (void *)NULL)
            ),
            mpClusters.end());
}
Esempio n. 14
0
PaintImageWidget::~PaintImageWidget()
{
    delete_safe(ui);
}