<commit_before>#include "module_webcams.h"
#include <Module_Webcams/form_webcams.h>
#include <assert.h>

Module_Webcams::Module_Webcams( QString id ) :
        RobotModule( id )
{
    leftFramerate = 5;
    rightFramerate = 5;
    bottomFramerate = 5;

    leftCap = NULL;
    rightCap = NULL;
    bottomCap = NULL;

    leftID = 1;
    rightID = 0;
    bottomID = 2;
}

Module_Webcams::~Module_Webcams()
{
    stopWebcams();
    cvReleaseImage( &leftFrame );
    cvReleaseImage( &rightFrame );
    cvReleaseImage( &bottomFrame );
}

void Module_Webcams::init()
{
    nCams = this->numAvailableCams();
    settingsChanged();
    leftFrame = cvCreateImage( cvSize( WEBCAM_WIDTH, WEBCAM_HEIGHT ), IPL_DEPTH_8U, 3 );
    rightFrame = cvCreateImage( cvSize( WEBCAM_WIDTH, WEBCAM_HEIGHT ), IPL_DEPTH_8U, 3 );
    bottomFrame = cvCreateImage( cvSize( WEBCAM_WIDTH, WEBCAM_HEIGHT ), IPL_DEPTH_8U, 3 );

}

void Module_Webcams::stopWebcams()
{
    if ( leftCap != NULL )
    {
        cvReleaseCapture(&leftCap);
        leftCap = NULL;
    }
    if ( rightCap != NULL )
    {
        cvReleaseCapture(&rightCap);
        rightCap = NULL;
    }
    if ( bottomCap != NULL  )
    {
        cvReleaseCapture(&bottomCap);
        bottomCap = NULL;
    }
}

void Module_Webcams::grabLeft( cv::Mat &left )
{
    if ( leftCap != NULL )
    {
        this->dataLockerMutex.lock();
        IplImage* img = cvQueryFrame(leftCap);
        if(img)
        {
            cvConvertImage(img,img,CV_CVTIMG_SWAP_RB);
        cv::Mat mtx(img);

        left = mtx.clone();
        }
        dataLockerMutex.unlock();
    }
}

void Module_Webcams::grabRight( cv::Mat &right )
{
    if ( rightCap != NULL )
    {
        dataLockerMutex.lock();
        IplImage* img = cvQueryFrame(rightCap);
        if(img)
        {
            cvConvertImage(img,img,CV_CVTIMG_SWAP_RB);
            cv::Mat mat(img);

            right = mat.clone();
        }
        dataLockerMutex.unlock();
    }
}

void Module_Webcams::grabBottom( cv::Mat &bottom )
{
    if ( bottomCap != NULL )
    {
        dataLockerMutex.lock();
        IplImage* img = cvQueryFrame(bottomCap);
        if(img)
        {
            cvConvertImage(img,img,CV_CVTIMG_SWAP_RB);
        cv::Mat mat(img);
        bottom = mat.clone();

        }
        dataLockerMutex.unlock();
    }
}

void Module_Webcams::grabLeft(IplImage *left)
{
    if(leftCap != NULL)
    {
        dataLockerMutex.lock();
        assert( left->width == WEBCAM_WIDTH && left->height == WEBCAM_HEIGHT );
        cvCopy(cvQueryFrame(leftCap),left);
        cvConvertImage(left,left,CV_CVTIMG_SWAP_RB);
        dataLockerMutex.unlock();
    }
}

void Module_Webcams::grabRight(IplImage *right)
{
    if(rightCap != NULL)
    {
        dataLockerMutex.lock();
        assert( right->width == WEBCAM_WIDTH && right->height == WEBCAM_HEIGHT );
        cvCopy(cvQueryFrame(rightCap),right);
        cvConvertImage(right,right,CV_CVTIMG_SWAP_RB);
        dataLockerMutex.unlock();
    }
}

void Module_Webcams::grabBottom(IplImage *bottom)
{
    if(bottomCap != NULL)
    {
        dataLockerMutex.lock();
        assert( bottom->width == WEBCAM_WIDTH && bottom->height == WEBCAM_HEIGHT );
        cvCopy(cvQueryFrame(bottomCap),bottom);
        cvShowImage("buhu",bottom);
        cvConvertImage(bottom,bottom,CV_CVTIMG_SWAP_RB);
        dataLockerMutex.unlock();
    }
}
//
//void Module_Webcams::grabBottom(QImage bottom1)
//{
//    cv::Mat bottom;
//    bottom.create( WEBCAM_HEIGHT, WEBCAM_WIDTH, CV_8UC3 );
//    if ( bottomConnected )//&& VI.isFrameNew(bottomID))
//    {<commit_msg>added mutex in stopWebcams<commit_after>#include "module_webcams.h"
#include <Module_Webcams/form_webcams.h>
#include <assert.h>

Module_Webcams::Module_Webcams( QString id ) :
        RobotModule( id )
{
    leftFramerate = 5;
    rightFramerate = 5;
    bottomFramerate = 5;

    leftCap = NULL;
    rightCap = NULL;
    bottomCap = NULL;

    leftID = 1;
    rightID = 0;
    bottomID = 2;
}

Module_Webcams::~Module_Webcams()
{
    stopWebcams();
    cvReleaseImage( &leftFrame );
    cvReleaseImage( &rightFrame );
    cvReleaseImage( &bottomFrame );
}

void Module_Webcams::init()
{
    nCams = this->numAvailableCams();
    settingsChanged();
    leftFrame = cvCreateImage( cvSize( WEBCAM_WIDTH, WEBCAM_HEIGHT ), IPL_DEPTH_8U, 3 );
    rightFrame = cvCreateImage( cvSize( WEBCAM_WIDTH, WEBCAM_HEIGHT ), IPL_DEPTH_8U, 3 );
    bottomFrame = cvCreateImage( cvSize( WEBCAM_WIDTH, WEBCAM_HEIGHT ), IPL_DEPTH_8U, 3 );

}

void Module_Webcams::stopWebcams()
{
    dataLockerMutex.lock();
    if ( leftCap != NULL )
    {
        cvReleaseCapture(&leftCap);
        leftCap = NULL;
    }
    if ( rightCap != NULL )
    {
        cvReleaseCapture(&rightCap);
        rightCap = NULL;
    }
    if ( bottomCap != NULL  )
    {
        cvReleaseCapture(&bottomCap);
        bottomCap = NULL;
    }
    dataLockerMutex.unlock();
}

void Module_Webcams::grabLeft( cv::Mat &left )
{
    dataLockerMutex.lock();
    if ( leftCap != NULL )
    {

        IplImage* img = cvQueryFrame(leftCap);
        if(img)
        {
            cvConvertImage(img,img,CV_CVTIMG_SWAP_RB);
            cv::Mat mtx(img);

            left = mtx.clone();
        }
        dataLockerMutex.unlock();
    }
}

void Module_Webcams::grabRight( cv::Mat &right )
{
    dataLockerMutex.lock();
    if ( rightCap != NULL )
    {

        IplImage* img = cvQueryFrame(rightCap);
        if(img)
        {
            cvConvertImage(img,img,CV_CVTIMG_SWAP_RB);
            cv::Mat mat(img);

            right = mat.clone();
        }
        dataLockerMutex.unlock();
    }
}

void Module_Webcams::grabBottom( cv::Mat &bottom )
{
    dataLockerMutex.lock();
    if ( bottomCap != NULL )
    {
        IplImage* img = cvQueryFrame(bottomCap);
        if(img)
        {
            cvConvertImage(img,img,CV_CVTIMG_SWAP_RB);
            cv::Mat mat(img);
            bottom = mat.clone();

        }
        dataLockerMutex.unlock();
    }
}

void Module_Webcams::grabLeft(IplImage *left)
{
    dataLockerMutex.lock();
    if(leftCap != NULL)
    {

        assert( left->width == WEBCAM_WIDTH && left->height == WEBCAM_HEIGHT );
        cvCopy(cvQueryFrame(leftCap),left);
        cvConvertImage(left,left,CV_CVTIMG_SWAP_RB);
        dataLockerMutex.unlock();
    }
}

void Module_Webcams::grabRight(IplImage *right)
{
    dataLockerMutex.lock();
    if(rightCap != NULL)
    {

        assert( right->width == WEBCAM_WIDTH && right->height == WEBCAM_HEIGHT );
        cvCopy(cvQueryFrame(rightCap),right);
        cvConvertImage(right,right,CV_CVTIMG_SWAP_RB);
        dataLockerMutex.unlock();
    }
}

void Module_Webcams::grabBottom(IplImage *bottom)
{
    dataLockerMutex.lock();
    if(bottomCap != NULL)
    {

        assert( bottom->width == WEBCAM_WIDTH && bottom->height == WEBCAM_HEIGHT );
        cvCopy(cvQueryFrame(bottomCap),bottom);
        cvShowImage("buhu",bottom);
        cvConvertImage(bottom,bottom,CV_CVTIMG_SWAP_RB);
        dataLockerMutex.unlock();
    }
}
//
//void Module_Webcams::grabBottom(QImage bottom1)
//{
//    cv::Mat bottom;
//    bottom.create( WEBCAM_HEIGHT, WEBCAM_WIDTH, CV_8UC3 );
//    if ( bottomConnected )//&& VI.isFrameNew(bottomID))
//    {
{'fraction_non_alphanumeric': 0.1310344827586207, 'fraction_numerical': 0.004137931034482759, 'mean_word_length': 2.643718592964824, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5202319', 'n_tokens_mistral': 2583, 'n_tokens_neox': 2573, 'n_words': 389}