53 sscanf(&supported[prev_idx],
"%dx%d", &tmp_width, &tmp_height);
156 double tick = (double)cv::getTickCount();
160 valid = mPI->read(mBuffer);
163 valid = mVI->read(mBuffer);
167 boost::upgrade_lock< boost::shared_mutex > lock(mMutex);
170 QScreen* screen = QGuiApplication::primaryScreen();
171 Qt::ScreenOrientation rotation = screen->orientation();
174 if ((rotation == Qt::LandscapeOrientation) && (
mIndex == 0))
176 cv::transpose(mBuffer, mCachedFrame);
177 cv::flip(mCachedFrame, mCachedFrame, 0);
179 else if ((rotation == Qt::LandscapeOrientation) && (
mIndex == 1))
181 cv::transpose(mBuffer, mCachedFrame);
183 else if ((rotation == Qt::PortraitOrientation) && (
mIndex == 1))
185 cv::flip(mBuffer, mCachedFrame, 1);
187 else if ((rotation == Qt::InvertedPortraitOrientation) && (
mIndex == 0))
189 cv::flip(mBuffer, mCachedFrame, -1);
191 else if ((rotation == Qt::InvertedPortraitOrientation) && (
mIndex == 1))
193 cv::flip(mBuffer, mCachedFrame, 0);
195 else if ((rotation == Qt::InvertedLandscapeOrientation) && (
mIndex == 0))
197 cv::transpose(mBuffer, mCachedFrame);
198 cv::flip(mCachedFrame, mCachedFrame, 1);
200 else if ((rotation == Qt::InvertedLandscapeOrientation) && (
mIndex == 1))
202 cv::transpose(mBuffer, mCachedFrame);
203 cv::flip(mCachedFrame, mCachedFrame, -1);
207 if (mBuffer.rows == mCachedFrame.rows && mBuffer.cols == mCachedFrame.cols)
208 memcpy(mCachedFrame.data, mBuffer.data, mBuffer.rows * mBuffer.cols * 3);
210 mBuffer.copyTo(mCachedFrame);
213 if (!mCachedFrame.empty() && (mBuffer.rows == mCachedFrame.rows && mBuffer.cols == mCachedFrame.cols))
214 memcpy(mCachedFrame.data, mBuffer.data, mBuffer.rows * mBuffer.cols * 3);
216 mBuffer.copyTo(mCachedFrame);
223 boost::upgrade_lock< boost::shared_mutex > lock(mMutex);
224 mCachedFrame.release();
229 tick = ((double)cv::getTickCount() - tick) / cv::getTickFrequency();
230 boost::this_thread::sleep_for(boost::chrono::milliseconds(std::max(16 - (
int)(tick * 1000), 0)));
237 throw std::logic_error(
"Device not initialised");
239 boost::upgrade_lock< boost::shared_mutex > lock(mMutex);
240 if (!mUpdated || mCachedFrame.empty())
245 throw std::logic_error(
"Device has bad pixel buffer");
261 if (mRetrieveBuffer.rows == mCachedFrame.rows && mRetrieveBuffer.cols == mCachedFrame.cols)
262 memcpy(mRetrieveBuffer.data, mCachedFrame.data, mCachedFrame.rows * mCachedFrame.cols * 3);
264 mCachedFrame.copyTo(mRetrieveBuffer);
267 return mRetrieveBuffer;
310 QScreen* screen = QGuiApplication::primaryScreen();
311 if (screen->primaryOrientation() == Qt::PortraitOrientation)
325 mBufferSize = cv::Size(width - (width % 320), height - (height % 240));
327 mBufferSize = cv::Size(width, height);
330 if ((mBufferSize.width != 0) && (mBufferSize.height != 0))
338 mPI->set(cv::CAP_PROP_FRAME_WIDTH, mBufferSize.width);
339 mPI->set(cv::CAP_PROP_FRAME_HEIGHT, mBufferSize.height);
345 mVI->set(cv::CAP_PROP_FRAME_WIDTH, mBufferSize.width);
346 mVI->set(cv::CAP_PROP_FRAME_HEIGHT, mBufferSize.height);
352 catch (std::exception &)
354 mBufferSize = cv::Size(640, 480);
359 mBufferSize = cv::Size(640, 480);
366 mBufferSize.width = mPI->get(cv::CAP_PROP_FRAME_WIDTH);
367 mBufferSize.height = mPI->get(cv::CAP_PROP_FRAME_HEIGHT);
372 mBufferSize.width = mVI->get(cv::CAP_PROP_FRAME_WIDTH);
373 mBufferSize.height = mVI->get(cv::CAP_PROP_FRAME_HEIGHT);
379 MMechostr(MSKRUNTIME,
"CameraInputOpenCV::SetSize: Creating output buffer with size %dx%d\n", mBufferSize.width, mBufferSize.height);
381 mBuffer = cv::Mat(mBufferSize.width, mBufferSize.height, CV_8UC3);
383 mBuffer = cv::Mat(mBufferSize.height, mBufferSize.width, CV_8UC3);
391 mBufferSize = cv::Size(width, height);
393 mBuffer = cv::Mat(mBufferSize.width, mBufferSize.height, CV_8UC3);
395 mBuffer = cv::Mat(mBufferSize.height, mBufferSize.width, CV_8UC3);
399 mCachedFrame.release();