Display the given image on the frame Copies the image so it is safe to change it after the function call
| 130 | // Display the given image on the frame |
| 131 | // Copies the image so it is safe to change it after the function call |
| 132 | void CaptureThread::SendFrame(IplImage *frame) |
| 133 | { |
| 134 | if (!frame) |
| 135 | { |
| 136 | return; |
| 137 | } |
| 138 | |
| 139 | IplImage* pDstImg; |
| 140 | CvSize sz = cvSize(frame->width, frame->height); |
| 141 | pDstImg = cvCreateImage(sz, 8, 3); |
| 142 | cvZero(pDstImg); |
| 143 | // convert the image into a 3 channel image for display on the frame |
| 144 | if (frame->nChannels == 1) |
| 145 | { |
| 146 | //cvCvtColor(frame, pDstImg, CV_GRAY2BGR); |
| 147 | |
| 148 | // another way to convert grayscale to RGB |
| 149 | cvMerge(frame, frame, frame, NULL, pDstImg); |
| 150 | } else if (frame->nChannels == 3){ |
| 151 | |
| 152 | // opencv stores images as BGR instead of RGB so we need to convert |
| 153 | cvConvertImage(frame, pDstImg, CV_CVTIMG_SWAP_RB); |
| 154 | |
| 155 | } else { |
| 156 | // we don't know how to display this image based on its number of channels |
| 157 | |
| 158 | // give up |
| 159 | cvReleaseImage( &pDstImg ); |
| 160 | return; |
| 161 | } |
| 162 | |
| 163 | wxCommandEvent event(IMAGE_UPDATE_EVENT, GetId()); |
| 164 | |
| 165 | // send the image in the event |
| 166 | event.SetClientData(pDstImg); |
| 167 | |
| 168 | // Send the event to the frame! |
| 169 | window->GetEventHandler()->AddPendingEvent(event); |
| 170 | } |