I am using opencv c++ to plot pixel value along a line in an frame in video. First, I use LineIterator to specify the considered line and then iterate through that line. Based on the LineIterator tutorial, I can print out the value of pixel value (pixelValues). Anyone know how to plot these pixel value when opening the video. Thank you very much.
This is my code’
void main() {
string video = "testVideo.MP4";
namedWindow("Video");
VideoCapture cap(video);
Mat frame, matrix, frameWarp;
float w = 700, h = 200;
while (1)
{
cap >> frame;
if (!frame.data)
break;
imshow("Video", frame);
Point2f src[4] = { {460,490},{858,499},{460,670},{858,670} };
Point2f dst[4] = { {0.0f,0.0f},{w,0.0f},{0.0f,h},{w,h} };
matrix = getPerspectiveTransform(src, dst);
warpPerspective(frame, frameWarp, matrix, Point(w, h));
LineIterator it(frameWarp, {0,123}, {700,123}, 8, true);
vector<Vec3b> pixelValues;
for (int i = 0; i < it.count; i++) {
pixelValues.push_back(Vec3b(*it));
it++;
}
line(frameWarp, { 0,123 }, { 700,123 }, Scalar(0, 255, 255), 2, LINE_4);
imshow("Image", frameWarp);
cout << Mat(pixelValues) << endl;
if (waitKey(300) >= 0)
break;