after merging and extracting the BGR channel, compilation is successful,but there is a run-time error: ILLEGAL OPERATION

asked 2018-08-22 01:42:45 -0500

nobot gravatar image

updated 2018-08-22 01:44:21 -0500

 #include <opencv2/opencv.hpp>
#include <stdio.h>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include<vector>
typedef cv::Vec3b Pixel;  //  correct


struct Operator {
    void operator ()(cv::Vec3b &pixel, const int * position) const 
    {    
            pixel[2]*=0.5; 
    }
}; 

int main(int argc, char** argv )
{
    cv::VideoCapture cap(0);
    if(!cap.isOpened())  
        return -1;
    cv::Mat frame1,frame2,for_each,cblue, cgreen, cred; 
    std::vector<cv::Mat> channels { cblue, cgreen, cred};
    for(;;)
    {
            cap >> frame1;    
            cvtColor(frame1, frame1, cv::COLOR_BGR2GRAY); 
            frame1.convertTo(frame2,CV_8U);

            frame2.copyTo(cblue);
            frame2.copyTo(cgreen);
            frame2.copyTo(cred);

            cv::merge(channels, for_each);

    double t1 = (double)cv::getTickCount();
    for_each.forEach<Pixel>(Operator());
    t1 = ((double)cv::getTickCount() - t1)/cv::getTickFrequency();
    std::cout<< "Parallel TEST time " << t1 << std::endl;

            cv::extractChannel (for_each, cblue, 0 );
            cv::imshow("cropped_BGR",frame1);
            cv::imshow("mod_BLUE",cblue);

    if (cv::waitKey(30) == 27) 
       {
            std::cout << "esc key is pressed by user" <<std::endl;
            break; 
       }
}
    return 0;

}
edit retag flag offensive close merge delete

Comments

it is based on one of my earlier post

nobot gravatar imagenobot ( 2018-08-22 01:47:09 -0500 )edit