简体   繁体   中英

opencv : Unable to read upper case letters through waitKey

I have a simple switch case as follows inside an infinite while loop, to call functions based on the key pressed by the user. I am programming in C++ using opencv libraries. The waitKey function used below is able to read the lower case letters i press on the keyboard. I am however unable to read any upper case letters and it still reads and interprets it as the corresponding lower case letter. Any help in this regard is appreciated. should i be updating my opencv libraries? I installed opencv on ubuntu with the help of this post

os UBUNTU 13.10 opencv version 2.4.8

Pseudo code

while(1)
{`
    char k = waitKey(0);
    switch(k) {
        case 'a' : ... break;
        case 'b' : ... break;
        case 'A' : ... break; // UNABLE TO READ A here.
    }
}

我在 OpenCV 论坛上发现了一个与您的问题相关的小提示,因为您还没有找到它: http : //answers.opencv.org/question/4266/cvwaitkey-upper-lowercase-difference/

I have the same problem (with opencv-4.x). I think this is due to the fact that I compiled opencv with the cmake option -D WITH_QT=ON (to enable the zoom scroll on images). But Qt interprets q and Q as the same keycode (81); the only thing is that it adds a (shift) modifier.

Let's say you receive a QKeyEvent event in a C++/Qt program. Then you get when pressing:

  • 'Q': event.key() = 81, event.modifiers().testFlag(Qt::KeyboardModifier::ShiftModifier) = true
  • 'q': event.key() = 81, event.modifiers().testFlag(Qt::KeyboardModifier::ShiftModifier) = false

It seems cv::waitKey or cv::waitKeyEx , when opencv uses Qt, does not read the modifiers, just the key code, unfortunately...

So far, the only option I found is to recompile with -D WITH_QT=OFF . Then I can discriminate between Q and q (but also left arrow and Shifted left arrow and so on). But the trade-off is that I can't scroll the images anymore...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM