Results 1 to 5 of 5

Thread: slider and color filtering or thresholding

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2014
    Posts
    4
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default slider and color filtering or thresholding

    hello guys,


    i want to make an app to track an Object.

    I am using opencv. I want change color threshold values using QSliders. However, i am unable to do so.
    Please see attached pic along with the code.

    Notice all the zeros in plainTextedit. Even if i change the slider position my variables ch1_min and others change. However, i still have 0 numbers for this in inRange function in the code.

    Please help.

    Qt Code:
    1. #include "dialog.h"
    2. #include "ui_dialog.h"
    3.  
    4. //////////////////////////////////////////////////////////////////////////
    5. /// \brief -> this is the Constructor
    6. /// \param parent
    7. //////////////////////////////////////////////////////////////////////////
    8.  
    9. Dialog::Dialog(QWidget *parent) : QDialog(parent), ui(new Ui::Dialog)
    10. {
    11. ui->setupUi(this);
    12. timer1 = new QTimer(this);
    13. connect(timer1, SIGNAL(timeout()), this, SLOT(ShowCamera()));
    14. ch1_min = ch2_min = ch3_min = 0;
    15. ch1_max = ch2_max = ch3_max = 255;
    16. }
    17. //////////////////////////////////////////////////////////////////////////
    18. /// \brief -> this is the Deconstructor
    19. //////////////////////////////////////////////////////////////////////////
    20. Dialog::~Dialog()
    21. {
    22. delete ui;
    23. }
    24. /////////////////////////////////////////////////////////////////////////////
    25. /// \brief Dialog::Dialog::paintEvent -> putText function
    26. /// \param e
    27. /////////////////////////////////////////////////////////////////////////////
    28. /*void Dialog::putText(QPaintEvent *e)
    29. {
    30.   QPainter painter(&tempframe);
    31.   QPen ourpen(Qt::magenta);
    32.   ourpen.setWidth(2);
    33.   painter.setPen(ourpen);
    34.   painter.setFont(QFont("Times", 20, QFont::Bold));
    35.   painter.drawText(outputView.rect(), "THIS!!"); ////////////// doesn't work
    36. }*/
    37. //////////////////////////////////////////////////////////////////////////////////////////////
    38. /// \brief Dialog::on_dispButton_clicked -> this function starts or stops the camera.
    39. ///
    40. ///
    41. /////////////////////////////////////////////////////////////////////////////////////////////
    42.  
    43. void Dialog::on_dispButton_clicked()
    44. {
    45. if(timer1->isActive() == true)
    46. {
    47. ui->dispButton->setText("Start camView");
    48. timer1->stop();
    49. cameraFeed.release();
    50. ui->camView->setText("Your camera view will be available here.");
    51.  
    52. }
    53. else
    54. {
    55. ui->dispButton->setText("Stop camView");
    56. timer1->start(30);
    57. Camera.open(0);
    58.  
    59. }
    60.  
    61. }
    62.  
    63.  
    64.  
    65. //////////////////////////////////////////////////////////////////////////////////////////////
    66. /// \brief all sliderMoved to change channel min and max
    67. /// \param ch1_min ch2_min ch3_min ch1_max ch2_max ch3_max
    68. /////////////////////////////////////////////////////////////////////////////////////////////
    69. void Dialog::on_ch1min_sliderMoved(int ch1_min)
    70. {
    71. ui->ch1min->valueChanged(ch1_min);
    72. if(ch1_min < ch1_max)
    73. {
    74.  
    75. ch1_min_string = QString::number(ch1_min);
    76. ui->dsp_ch1_min->clear();
    77. ui->dsp_ch1_min->appendPlainText(ch1_min_string);
    78. }
    79. else
    80. {
    81. ch1_min = ch1_max-1;
    82. ui->ch1min->valueChanged(ch1_min);
    83. ch1_min_string = QString::number(ch1_min);
    84. ui->dsp_ch1_min->clear();
    85. ui->dsp_ch1_min->appendPlainText(ch1_min_string);
    86. }
    87. }
    88.  
    89. void Dialog::on_ch2min_sliderMoved(int ch2_min)
    90. {
    91. ui->ch2min->valueChanged(ch2_min);
    92. if(ch2_min < ch2_max)
    93. {
    94.  
    95. ch2_min_string = QString::number(ch2_min);
    96. ui->dsp_ch2_min->clear();
    97. ui->dsp_ch2_min->appendPlainText(ch2_min_string);
    98. }
    99. else
    100. {
    101. ch2_min = ch2_max-1;
    102. ui->ch2min->valueChanged(ch2_min);
    103. ch2_min_string = QString::number(ch2_min);
    104. ui->dsp_ch2_min->clear();
    105. ui->dsp_ch2_min->appendPlainText(ch2_min_string);
    106. }
    107. }
    108.  
    109. void Dialog::on_ch3min_sliderMoved(int ch3_min)
    110. {
    111. ui->ch3min->valueChanged(ch3_min);
    112. if(ch3_min < ch3_max)
    113. {
    114.  
    115. ch3_min_string = QString::number(ch3_min);
    116. ui->dsp_ch3_min->clear();
    117. ui->dsp_ch3_min->appendPlainText(ch3_min_string);
    118. }
    119. else
    120. {
    121. ch3_min = ch3_max-1;
    122. ui->ch3min->valueChanged(ch3_min);
    123. ch3_min_string = QString::number(ch3_min);
    124. ui->dsp_ch3_min->clear();
    125. ui->dsp_ch3_min->appendPlainText(ch3_min_string);
    126. }
    127. }
    128.  
    129. void Dialog::on_ch1max_sliderMoved(int ch1_max)
    130. {
    131. ui->ch1max->valueChanged(ch1_max);
    132. if(ch1_max > ch1_min)
    133. {
    134. ch1_max_string = QString::number(ch1_max);
    135. ui->dsp_ch1_max->clear();
    136. ui->dsp_ch1_max->appendPlainText(ch1_max_string);
    137. }
    138. else
    139. {
    140. ch1_max= ch1_min+1;
    141. ch1_max_string = QString::number(ch1_max);
    142. ui->dsp_ch1_max->clear();
    143. ui->dsp_ch1_max->appendPlainText(ch1_max_string);
    144. }
    145.  
    146. }
    147.  
    148. void Dialog::on_ch2max_sliderMoved(int ch2_max)
    149. {
    150. ui->ch2max->valueChanged(ch2_max);
    151. if(ch2_max>ch2_min)
    152. {
    153. ch2_max_string = QString::number(ch2_max);
    154. ui->dsp_ch2_max->clear();
    155. ui->dsp_ch2_max->appendPlainText(ch2_max_string);
    156. }
    157. else
    158. {
    159. ch2_max = ch2_min+1;
    160. ch2_max_string = QString::number(ch2_max);
    161. ui->dsp_ch2_max->clear();
    162. ui->dsp_ch2_max->appendPlainText(ch2_max_string);
    163. }
    164. }
    165.  
    166. void Dialog::on_ch3max_sliderMoved(int ch3_max)
    167. {
    168. ui->ch3max->valueChanged(ch3_max);
    169. if(ch3_max>ch3_min)
    170. {
    171. ch3_max_string = QString::number(ch3_max);
    172. ui->dsp_ch3_max->clear();
    173. ui->dsp_ch3_max->appendPlainText(ch3_max_string);
    174. }
    175. else
    176. {
    177. ch3_max=ch3_min+1;
    178. ch3_max_string = QString::number(ch3_max);
    179. ui->dsp_ch3_max->clear();
    180. ui->dsp_ch3_max->appendPlainText(ch3_max_string);
    181. }
    182. }
    183.  
    184. ////////////////////////////////////////////////////////////////////////////////////////////////
    185. /// \brief Dialog::ShowCamera -> here we read frames and show them in label called camView
    186. /// temp is used only to make use of visual representation of image in Qt using QImage.
    187. ///
    188. ////////////////////////////////////////////////////////////////////////////////////////////////
    189. void Dialog::ShowCamera()
    190. {
    191. Camera.read(cameraFeed);
    192.  
    193. ui->plainTextEdit->appendPlainText((QString::number(ch1_min))); ////this is the reason of all the zeros in plainTextEdit. for this function changed values do not appear updated
    194.  
    195. cv::inRange(cameraFeed,cv::Scalar(ch1_min,ch2_min,ch3_min),cv::Scalar(ch1_max,ch2_max,ch3_max),thresholdFeed);
    196. if(cameraFeed.empty() == true) return;
    197.  
    198. ////////////////// visualization of image acquired from camera
    199.  
    200. cameraFeed.copyTo(temp);
    201. cv::cvtColor(temp, temp, CV_BGR2RGB);
    202. QImage qimgOriginal((uchar*) temp.data, temp.cols, temp.rows, temp.step, QImage::Format_RGB888);
    203.  
    204.  
    205. ////////////////// visualization of binary image
    206.  
    207. QImage qimgProcessed((uchar*) thresholdFeed.data, thresholdFeed.cols, thresholdFeed.rows, thresholdFeed.step, QImage::Format_Indexed8);
    208. ui->camView->setPixmap(QPixmap::fromImage(qimgOriginal));
    209. ui->outputView->setPixmap(QPixmap::fromImage(qimgProcessed));
    210.  
    211.  
    212.  
    213. }
    To copy to clipboard, switch view to plain text mode 
    Attached Images Attached Images

Similar Threads

  1. change part of a slider color in video cutter tool
    By DURGAPRASAD NEELAM in forum Qt Programming
    Replies: 1
    Last Post: 22nd April 2014, 06:51
  2. Dynamic label to right of slider resizes slider
    By zenzero-2001 in forum Qt Programming
    Replies: 2
    Last Post: 3rd October 2013, 10:11
  3. Event filtering
    By Cruz in forum Qt Programming
    Replies: 6
    Last Post: 28th March 2011, 12:35
  4. Key filtering
    By phillip_Qt in forum Qt Programming
    Replies: 2
    Last Post: 24th June 2010, 09:10
  5. Replies: 2
    Last Post: 21st March 2010, 09:01

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.