Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7555291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:34:13+00:00 2026-05-30T11:34:13+00:00

I am attaching some parts of my code, #include mainwindow.h #include ui_mainwindow.h #include colorrecognition.h

  • 0

I am attaching some parts of my code,

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "colorrecognition.h"


MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
 {

ui->setupUi(this);
//this->setStyleSheet("background-color: black;"); // set the background
//capture = 0;
// frame = 0;


//interface
//tabWidget = new QTabWidget;



//start capturing a video
//capture = cvCaptureFromCAM(0);
//capture = cvCaptureFromAVI("videoExample.avi");




//frame = cvQueryFrame(capture);

tabWidget = new QTabWidget(ui->centralWidget);
tabWidget->setObjectName(QString::fromUtf8("tabWidget"));
tabWidget->setGeometry(QRect(20, 0, 801, 571));
tabWidget->addTab(new ColorRecognition(), tr("Color Recognition"));

Contour contour1;



}


MainWindow::~MainWindow()
{
    delete ui;
}


//========================================================


ColorRecognition::ColorRecognition(QWidget *parent){

storage1 = cvCreateMemStorage(0);

storage2 = cvCreateMemStorage(0);

 /*QFrame* frame1 = new QFrame(this);
 frame1->setObjectName(QString::fromUtf8("frame1"));
 frame1->setGeometry(QRect(20, 20, 761, 501));
 frame1->setFrameShape(QFrame::StyledPanel);
 frame1->setFrameShadow(QFrame::Raised);*/

 //start capturing a video
 capture = cvCaptureFromCAM(0);
 //capture = cvCaptureFromAVI("videoExample.avi");

 //print an error message in case you can't grab the frame
 if (!cvGrabFrame(capture)) { // capture a frame
         printf("couldn't grab a frame");
 }


 //First screen --- Color Identification ---

//QObject::connect(ui->tabWidget, SIGNAL(currentChanged(int)), this, SLOT(color_Recoginition()));


 //set timer for 50ms intervals

 QTimer* m_timer = new QTimer(this);

 connect(m_timer, SIGNAL(timeout()), this, SLOT(color()));

 m_timer->start(100);
}

    void ColorRecognition::paintEvent(QPaintEvent* e) {

    QPainter painter(this);

    painter.drawImage(10,10, qt_img);
}



void ColorRecognition::color(){

   frame = cvQueryFrame(capture);

   //CvSize imageSize = cvSize(frame->width,frame->height);

  //IplImage* resultImage = cvCreateImage(imageSize, 8, 3);

  //qDebug("Befroe manipulation");

  cvCvtColor(frame, frame, CV_BGR2RGB);

//CvSize imageSize = cvSize(frame->width, frame->height);

IplImage  **thresholdedImage = contour1.GetThresholdedImage(frame);

//insert the resulted frame from the above function into the find contour function

cvFindContours(thresholdedImage[0], storage1, &contours1, sizeof(CvContour),
            CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, cvPoint(0, 0));

cvFindContours(thresholdedImage[1], storage2, &contours2, sizeof(CvContour),
            CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, cvPoint(0, 0));

contour1.drawContour(contours1, storage1, frame, CV_RGB(255, 0, 0));

contour1.drawContour(contours2, storage2, frame, CV_RGB(0, 255, 0));


qt_img = QImage((unsigned char *)frame->imageDataOrigin,frame->width,frame->height,QImage::Format_RGB888);


    //release temp memory

    //cvReleaseMemStorage(&storage1);

    //cvReleaseMemStorage(&storage2);

    //cvReleaseMemStorage(&contours1->storage); // check if that is correct

    //cvReleaseMemStorage(&contours2->storage);*/


//resultImage = contour1.colorIdentification(frame);

//cvCvtColor(resultImage, resultImage, CV_BGR2RGB);

//qDebug("After manipulation");



this->update();

}

the problem is that when I run this code I don’t get anything on the screen, however when I run the code out Qt (only in OpenCV) the code was working with no problems

Can anyone know what is the deal ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T11:34:14+00:00Added an answer on May 30, 2026 at 11:34 am

    so I figured out what went wrong in my code, it is really a silly mistake –>

    I was passing the frame image immediately to the function I have done

    frame = cvQueryFrame(capture);
    

    so what solved my problem was copying the frame image into an IplImage and then it worked perfectly –>

    cvCopy(frame, resultImage);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attaching an image. Some of you might have tried this iphone application
I'm attaching a new database programatically using VB.net application. I wrote DB scripts and
I am attaching a method to the post_save signal of my Django model. This
How does one go about attaching a bunch of code to an onkeydown event,
I've been using the macro from this blog entry for attaching the Visual Studio
After reading some posts like this one: Choose File Dialog It appears that Android
We're starting new web site development with Umbraco, and having some difficulties with optimal
Is there a cross browser method of attaching some content in a <div> to
I am testing some code that has a client exe and a server exe
I have some checkboxes dynamically created in C# codebehind. Let's say two columns. This

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.