Bonjour !

J'aimerai recuperer le flux de ma webcam (macbookpro)

J'ai fait quelques recherche et j'ai vu que cela n'etait pas si simple ...

A la base je voullais le faire en Java (pour etre au maximum multiplateforme) et j ai vu le framework JMF qui a priori permetait de faire des trucs sympa et facilement mais pas sous mac ...

Je me suis orienté vers QTJava qui est un peu violent et j'ai trouvé du code qui récupere et l'affiche dans du awt ... mais l'image est totalement bleu ! (le framework est en 6.x et quick time en 7.x peut etre que cela vient de ça)

Bref ... vous avez des solution pour exploiter cette webcam ?

Merci !

PS je joins le code pour exploiter la webcam (ca pourra en interresser) :

Code java : 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import java.util.*;
import quicktime.*;
import quicktime.std.sg.*;
import quicktime.std.*;
import quicktime.qd.*;
import quicktime.util.*;
import quicktime.io.*;
import quicktime.std.image.*;
import quicktime.std.movies.*;
 
 
import quicktime.std.qtcomponents.*;
import quicktime.app.view.*;
 
 
 
import java.awt.*;
import java.awt.image.*;
import javax.swing.*;
 
 
 
public class DataProcTest {
 
 
    public static void main(String args[]) {
        try{
            QTSession.open();
 
 
// Setting up the Sequence Grabber
            final SequenceGrabber sg = new SequenceGrabber();
            final SGVideoChannel vc = new SGVideoChannel(sg);
            final QDRect cameraImageSize = new QDRect(320, 240); // vc.getSrcVideoBounds();
            final QDGraphics gWorld = new QDGraphics(cameraImageSize);
 
 
            sg.setGWorld(gWorld, null);
            vc.setBounds(cameraImageSize);
            vc.setUsage(quicktime.std.StdQTConstants.seqGrabRecord );
            vc.setFrameRate(24);
            final int myCodec = quicktime.std.StdQTConstants.kComponentVideoCodecType ;
            vc.setCompressorType(myCodec);
 
// Setting up the buffered image
            int size = gWorld.getPixMap().getPixelData().getSize();
            int intsPerRow = gWorld.getPixMap().getPixelData().getRowBytes()/4;
            size = intsPerRow*cameraImageSize.getHeight();
            final int[] pixelData = new int[size];
            DataBuffer db = new DataBufferInt(pixelData, size);
            ColorModel colorModel = new DirectColorModel(32, 0x00ff0000, 0x0000ff00, 0x000000ff);
            int[] masks= {0x00ff0000, 0x0000ff00, 0x000000ff};
            //int[] masks = {0x00000000, 0x00000000, 0x00000000};
            WritableRaster raster = Raster.createPackedRaster(db, cameraImageSize.getWidth(), cameraImageSize.getHeight(), intsPerRow, masks, null);
            final BufferedImage image = new BufferedImage(colorModel, raster, false, null);
 
 
// Setting up a component, capable of displaying the image
            class MyComp extends Component{
                public void paint(Graphics g){
                    super.paint(g);
                    g.drawImage(image, 0, 0, this);
                };
            };
            final MyComp ret = new MyComp();
            Frame myFrame = new Frame("Test");
            myFrame.setBounds(100, 100, cameraImageSize.getWidth(), cameraImageSize.getHeight());
            myFrame.add(ret);
            myFrame.show();
 
//Defining the data procedure which pushes the data into the image
            SGDataProc myDataProc = new SGDataProc(){
                DSequence ds = null;
                final Matrix idMatrix=new Matrix();
                byte[] rawData = new byte[
                        QTImage.getMaxCompressionSize(
                        gWorld,
                        gWorld.getBounds(),
                        0,
                        quicktime.std.StdQTConstants.codecLowQuality,
                        myCodec,
                        CodecComponent.anyCodec)
                        ];
                RawEncodedImage ri = null;
                public int execute(SGChannel chan, QTPointerRef dataToWrite, int offset, int chRefCon, int time, int writeType){
                    if (chan instanceof SGVideoChannel) try{
                        ImageDescription id = vc.getImageDescription();
                        if(rawData==null) rawData = new byte [dataToWrite.getSize()];
                        RawEncodedImage ri = new RawEncodedImage(rawData);
                        dataToWrite.copyToArray(0, rawData, 0, dataToWrite.getSize());
                        if(ds==null){
                            ds = new DSequence(id,
                                    ri,
                                    gWorld,
                                    cameraImageSize,
                                    idMatrix,
                                    null,
                                    0,
                                    quicktime.std.StdQTConstants.codecNormalQuality,
                                    CodecComponent.anyCodec);
                        }else{
                            ds.decompressFrameS(ri, quicktime.std.StdQTConstants.codecNormalQuality);
                        }
                        gWorld.getPixMap().getPixelData().copyToArray(0, pixelData, 0, pixelData.length);
                        ret.repaint();
                        return 0;
 
                    }catch(Exception ex){
 
 
                        ex.printStackTrace();
                        return 1;
 
 
                    } else return 1;
                }
 
 
            };
 
 
            sg.setDataProc(myDataProc);
 
 
// Preparing for output
            sg.setDataOutput(null, quicktime.std.StdQTConstants.seqGrabDontMakeMovie);
            sg.prepare(false, true);
            sg.startRecord();
 
            // setting up a thread, to idle the sequence grabber
            Runnable idleCamera = new Runnable(){
                public void run(){
                    try{
                        while(true){
                            sg.idleMore();
                            sg.update(null);
                            try {
                                Thread.sleep(42);
                            } catch (InterruptedException ex) {
                                ex.printStackTrace();
                            }
                        }
                    }catch(Exception ex){
                        ex.printStackTrace();
                    }
                }
            };
 
 
            (new Thread(idleCamera)).start();
 
 
        }catch(Exception ex){
            ex.printStackTrace();
            QTSession.close();
        }
    }
}