Bonjour,
mon code sans la fonction conversion Mat2Qimage fonctionne avec imshow.
Par contre l'objectif est d'afficher un fichier avi ou la webcam par le biais de la bibliothèque opencv.

le format est Mat alors que pour le Qlabel il faut passer par QPixmap j'utilise donc la fonction de conversion mais et je réalise l'affectation dans le label.

Mais la compilation se plante avec les erreurs reprises en bas.
voici les différentes sources

1_qtopencv.pro
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
QT       += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = 1_qt
CONFIG   -= app_bundle
 
TEMPLATE = app
 
CONFIG += console
 
SOURCES += main.cpp \
    main.cpp
 
INCLUDEPATH += E:\opencv\build\include\

LIBS += -LE:\opencv\build\bin \
    -lopencv_core244 \
    -lopencv_highgui244 \
    -lopencv_imgproc244 \
    -lopencv_features2d244 \
    -lopencv_calib3d244 \
    -lopencv_contrib244 \
    -lopencv_flann244 \
    -lopencv_gpu244 \
    -lopencv_legacy244 \
    -lopencv_ml244 \
    -lopencv_nonfree244 \
    -lopencv_objdetect244 \
    -lopencv_photo244 \
    -lopencv_stitching244 \
    -lopencv_video244 \
    -lopencv_videostab244 \
main.cpp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <QApplication>
#include <QtWidgets>
#include <opencv2/opencv.hpp>
#include <iostream>
#include <stdio.h>
#include <opencv2/core/core_c.h>
 
 
using namespace cv;
using namespace std;
 
QImage Mat2QImage(const cv::Mat &image)
{
        QImage qtemp;
        if(!image.empty() && image.depth() == CV_8U)
        {
                const unsigned char * data = image.data;
                qtemp = QImage(image.cols, image.rows, QImage::Format_RGB32);
                for(int y = 0; y < image.rows; ++y, data += image.cols*image.elemSize())
                {
                        for(int x = 0; x < image.cols; ++x)
                        {
                                QRgb * p = ((QRgb*)qtemp.scanLine (y)) + x;
                                *p = qRgb(data[x * image.channels()+2], data[x * image.channels()+1], data[x * image.channels()]);
                        }
                }
        }
        else if(!image.empty() && image.depth() != CV_8U)
        {
                printf("Mauvais format, doit être en 8_bits\n");
        }
        return qtemp;
}
 
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QWidget fenetre;
    fenetre.setGeometry(20,20,1064,810);
    QLabel *label = new QLabel(&fenetre);
    label->move(20,20);
 
    VideoCapture cap;
    //cap.open("d:/cube4.avi");
    cap.open(0);
    cout<<cap.isOpened()<<endl;
 
    namedWindow("window",1);
    Mat m;
    Mat cvImage_;
    QPixmap pixmap_;
    while(cap.read(m))
    {
        cvImage_ = m.clone();
      //  pixmap_ = QPixmap::fromImage(Mat2QImage(cvImage_));
 
        imshow("window",m);
 
        waitKey(33);
 
        label->setPixmap(pixmap_);
        fenetre.show();
    }
 
    return app.exec();
}
sortie :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
11:33:30: Exécution des étapes pour le projet 1_qtopencv...
11:33:30: Configuration inchangée, étape QMake sautée.
11:33:30: Débute : "C:\Qt\Qt5.0.1\Tools\MinGW\bin\mingw32-make.exe" 
C:/Qt/Qt5.0.1/Tools/MinGW/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory 'E:/Users/compo/Documents/qt/1_qtopencv-build-Desktop_Qt_5_0_1_MinGW_32bit-Debug'
Makefile.Debug:1086: warning: overriding recipe for target 'debug/main.o'
Makefile.Debug:603: warning: ignoring old recipe for target 'debug/main.o'
g++ -Wl,-subsystem,console -mthreads -o debug\1_qt.exe debug/main.o debug/main.o  -LE:\opencv\build\bin -lopencv_core244 -lopencv_highgui244 -lopencv_imgproc244 -lopencv_features2d244 -lopencv_calib3d244 -lopencv_contrib244 -lopencv_flann244 -lopencv_gpu244 -lopencv_legacy244 -lopencv_ml244 -lopencv_nonfree244 -lopencv_objdetect244 -lopencv_photo244 -lopencv_stitching244 -lopencv_video244 -lopencv_videostab244 -LC:\Qt\Qt5.0.1\5.0.1\mingw47_32\lib -lQt5Widgetsd -lQt5Guid -lQt5Cored -llibEGLd -llibGLESv2d -lgdi32 -luser32 
debug/main.o: In function `Z10Mat2QImageRKN2cv3MatE':
E:\Users\compo\Documents\qt\1_qtopencv-build-Desktop_Qt_5_0_1_MinGW_32bit-Debug/../1_qtopencv/main.cpp:13: multiple definition of `Mat2QImage(cv::Mat const&)'
debug/main.o:E:\Users\compo\Documents\qt\1_qtopencv-build-Desktop_Qt_5_0_1_MinGW_32bit-Debug/../1_qtopencv/main.cpp:13: first defined here
debug/main.o: In function `main':
E:\Users\compo\Documents\qt\1_qtopencv-build-Desktop_Qt_5_0_1_MinGW_32bit-Debug/../1_qtopencv/main.cpp:36: multiple definition of `main'
debug/main.o:E:\Users\compo\Documents\qt\1_qtopencv-build-Desktop_Qt_5_0_1_MinGW_32bit-Debug/../1_qtopencv/main.cpp:36: first defined here
collect2.exe: error: ld returned 1 exit status
Makefile.Debug:79: recipe for target 'debug\1_qt.exe' failed
mingw32-make[1]: *** [debug\1_qt.exe] Error 1
mingw32-make[1]: Leaving directory 'E:/Users/compo/Documents/qt/1_qtopencv-build-Desktop_Qt_5_0_1_MinGW_32bit-Debug'
makefile:34: recipe for target 'debug' failed
mingw32-make: *** [debug] Error 2
11:33:33: Le processus "C:\Qt\Qt5.0.1\Tools\MinGW\bin\mingw32-make.exe" s'est terminé avec le code 2.
Error while building/deploying project 1_qtopencv (kit: Desktop Qt 5.0.1 MinGW 32bit)
Lors de l'exécution de l'étape "Make"
Merci