I am making Langton's Ant in C++, when I try to draw squares, I can. But I can't make this in loop.
for(int i = 0;i<=100;i++){
rectangle( image, Point( i*5, 0 ), Point( (i*5)+5, 5), Scalar( 0, 55, 255 ), CV_FILLED, 4 );
imshow("kare",image);
Sleep(100);
}
It waits for 10 seconds, then draw all the squares same time. If I add cvWaitKey(0); before sleep, I get same problem. When I "touch" the key, it draw, but when I hold, it doesn't draw. When I back off my finger, it draw.
How can I solve it? Regards.
You are mixing C and C++ API, cvWaitKey(0) belongs to deprecated C. Also cvWaitKey(0) waits until user press key.
So just use
waitKey(33) instead of sleep(), which will wait 33 ms after each imshow().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With