Restored function to rescale pixel values before imshow
This commit is contained in:
@@ -123,4 +123,39 @@ double cvGetOpenGlProp_QT(const char* name);
|
||||
double cvGetPropVisible_QT(const char* name);
|
||||
#endif
|
||||
|
||||
inline void convertToShow(const cv::Mat &src, cv::Mat &dst, bool toRGB = true)
|
||||
{
|
||||
const int src_depth = src.depth();
|
||||
CV_Assert(src_depth != CV_16F && src_depth != CV_32S);
|
||||
cv::Mat tmp;
|
||||
switch(src_depth)
|
||||
{
|
||||
case CV_8U:
|
||||
tmp = src;
|
||||
break;
|
||||
case CV_8S:
|
||||
cv::convertScaleAbs(src, tmp, 1, 127);
|
||||
break;
|
||||
case CV_16S:
|
||||
cv::convertScaleAbs(src, tmp, 1/255., 127);
|
||||
break;
|
||||
case CV_16U:
|
||||
cv::convertScaleAbs(src, tmp, 1/255.);
|
||||
break;
|
||||
case CV_32F:
|
||||
case CV_64F: // assuming image has values in range [0, 1)
|
||||
cv::convertScaleAbs(src, tmp, 256.);
|
||||
break;
|
||||
}
|
||||
cv::cvtColor(tmp, dst, toRGB ? cv::COLOR_BGR2RGB : cv::COLOR_BGRA2BGR, dst.channels());
|
||||
}
|
||||
|
||||
inline void convertToShow(const cv::Mat &src, const CvMat* arr, bool toRGB = true)
|
||||
{
|
||||
cv::Mat dst = cv::cvarrToMat(arr);
|
||||
convertToShow(src, dst, toRGB);
|
||||
CV_Assert(dst.data == arr->data.ptr);
|
||||
}
|
||||
|
||||
|
||||
#endif /* __HIGHGUI_H_ */
|
||||
|
||||
@@ -2556,17 +2556,7 @@ void DefaultViewPort::updateImage(const CvArr* arr)
|
||||
|
||||
nbChannelOriginImage = cvGetElemType(mat);
|
||||
CV_Assert(origin == 0);
|
||||
cv::Mat src = cv::cvarrToMat(mat), dst = cv::cvarrToMat(image2Draw_mat);
|
||||
|
||||
cv::Mat tmp;
|
||||
int src_depth = src.depth();
|
||||
double scale = src_depth <= CV_8S ? 1 : src_depth <= CV_32S ? 1./256 : 255;
|
||||
double shift = src_depth == CV_8S || src_depth == CV_16S ? 128 : 0;
|
||||
cv::convertScaleAbs(src, tmp, scale, shift);
|
||||
|
||||
cv::cvtColor(tmp, dst, cv::COLOR_BGR2RGB, dst.channels());
|
||||
CV_Assert(dst.data == image2Draw_mat->data.ptr);
|
||||
|
||||
convertToShow(cv::cvarrToMat(mat), image2Draw_mat);
|
||||
viewport()->update();
|
||||
}
|
||||
|
||||
|
||||
@@ -946,7 +946,7 @@ static NSSize constrainAspectRatio(NSSize base, NSSize constraint) {
|
||||
|
||||
if (bitmap) {
|
||||
cv::Mat dst(arrMat.rows, arrMat.cols, CV_8UC3, [bitmap bitmapData], [bitmap bytesPerRow]);
|
||||
cv::cvtColor(arrMat, dst, cv::COLOR_BGR2RGB);
|
||||
convertToShow(arrMat, dst);
|
||||
}
|
||||
else {
|
||||
// It's not guaranteed to like the bitsPerPixel:24, but this is a lot slower so we'd rather not do it
|
||||
@@ -960,8 +960,8 @@ static NSSize constrainAspectRatio(NSSize base, NSSize constraint) {
|
||||
colorSpaceName:NSDeviceRGBColorSpace
|
||||
bytesPerRow:(arrMat.cols * 4)
|
||||
bitsPerPixel:32];
|
||||
cv::Mat dst(arrMat.rows, arrMat.cols, CV_8UC3, [bitmap bitmapData], [bitmap bytesPerRow]);
|
||||
cv::cvtColor(arrMat, dst, cv::COLOR_BGR2RGBA);
|
||||
cv::Mat dst(arrMat.rows, arrMat.cols, CV_8UC4, [bitmap bitmapData], [bitmap bytesPerRow]);
|
||||
convertToShow(arrMat, dst);
|
||||
}
|
||||
|
||||
if( image ) {
|
||||
|
||||
@@ -141,9 +141,7 @@ void cvImageWidgetSetImage(CvImageWidget * widget, const CvArr *arr){
|
||||
gtk_widget_queue_resize( GTK_WIDGET( widget ) );
|
||||
}
|
||||
CV_Assert(origin == 0);
|
||||
cv::Mat src = cv::cvarrToMat(arr), dst = cv::cvarrToMat(widget->original_image);
|
||||
cv::cvtColor(src, dst, cv::COLOR_BGR2RGB, dst.channels());
|
||||
CV_Assert(dst.data == widget->original_image->data.ptr);
|
||||
convertToShow(cv::cvarrToMat(arr), widget->original_image);
|
||||
if(widget->scaled_image){
|
||||
cvResize( widget->original_image, widget->scaled_image, CV_INTER_AREA );
|
||||
}
|
||||
|
||||
@@ -1206,18 +1206,10 @@ cvShowImage( const char* name, const CvArr* arr )
|
||||
}
|
||||
|
||||
{
|
||||
cv::Mat src = cv::cvarrToMat(image);
|
||||
cv::Mat dst(size.cy, size.cx, CV_8UC3, dst_ptr, (size.cx * channels + 3) & -4);
|
||||
|
||||
cv::Mat tmp;
|
||||
int src_depth = src.depth();
|
||||
double scale = src_depth <= CV_8S ? 1 : src_depth <= CV_32S ? 1./256 : 255;
|
||||
double shift = src_depth == CV_8S || src_depth == CV_16S ? 128 : 0;
|
||||
cv::convertScaleAbs(src, tmp, scale, shift);
|
||||
cv::cvtColor(tmp, dst, cv::COLOR_BGRA2BGR, dst.channels());
|
||||
cv::flip(dst, dst, 0);
|
||||
|
||||
convertToShow(cv::cvarrToMat(image), dst, false);
|
||||
CV_Assert(dst.data == (uchar*)dst_ptr);
|
||||
cv::flip(dst, dst, 0);
|
||||
}
|
||||
|
||||
// ony resize window if needed
|
||||
|
||||
Reference in New Issue
Block a user