When I try to access the value of each pixel in a frame in a video the frame becomes gray

Viewed 42

When I try to print the value of each pixel of a frame in a video everything goes gray and the rgb values becomes [1, 1, 1].

Originally I wanted to iterate through every pixel by using a nested for loop, but apparently I can't access the value of more than 1 pixel per frame

    VideoCapture vid_capture("Bad Apple.mp4");
    if (!vid_capture.isOpened())
    {
        cout << "Error opening video stream or file" << endl;
    }
    cv::Mat frame, snapshot;
    vid_capture.read(frame);
    int keyVal;
    while (1) {
        if (!vid_capture.read(frame)) {
            break;
        }
        cv::imshow("Video", frame);
        
        //if I try to print every value of the frame matrix it suddenly becomes [1, 1, 1]
        cout << frame;

        //if I don't have this code everything goes gray ;-;
        //from https://nrsyed.com/2018/02/12/get-pixel-rgb-value-from-webcam-video-in-opencv-c-and-python/
        keyVal = cv::waitKey(1) & 0xFF;
        if (keyVal == 113) {
            break;
        }
        else if (keyVal == 116) {
            snapshot = frame;
            cv::imshow("Snapshot", snapshot);
        }
    }
    return 0;

I want to clarify that the cout << frame; is there just to show that I can't access more than 1 pixel value per frame, I also tried this:

{
    cv::Mat* snapshot = (cv::Mat*)ptr;
    cv::Vec3b pixel = snapshot->at<cv::Vec3b>(cv::Point(i, j));
    return pixel;
}

int main()
{
    system("mode 480, 360");
    VideoCapture vid_capture("Bad Apple.mp4");
    if (!vid_capture.isOpened())
    {
        cout << "Error opening video stream or file" << endl;
    }
    cv::Mat frame, snapshot;
    vid_capture.read(frame);
    int keyVal;
    while (1) {
        if (!vid_capture.read(frame)) {
            break;
        }
        cv::imshow("Video", frame);
        
        //if I try to print every value of the frame matrix it suddenly becomes [1, 1, 1]
        for (int i = 0; i < frame.rows; i++)
        {
            for (int j = 0; j < frame.cols; j++)
            {
                cout << checkPixelColor(&frame, i, j);
            }
        }

        //if I don't have this code everything goes gray ;-;
        keyVal = cv::waitKey(1) & 0xFF;
        if (keyVal == 113) {
            break;
        }
        else if (keyVal == 116) {
            snapshot = frame;
            cv::imshow("Snapshot", snapshot);
        }
    }
    return 0;
}

since you guys asked I'll upload some of the frames in .png this is a frame from the video

another frame third and last frame :D

since you've been asking I'll put a video showing what is happening [I have no clue why it does that :( ] this is the video

0 Answers
Related