Full image not coming using imshow - c++

I have an image of dimension 4096 X 2304. I can view that Image when double click.
Then i wanted to write my own opencv (ver 2.4.3) program to display this image. But The image is not fitting on the screen. It is showing only 50%, rest of the part is cutting.
This my code for image display:
#include "stdafx.h"
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main()
{
Mat im = imread("1.jpg");
if (im.empty())
{
cout << "Cannot load image!" << endl;
return -1;
}
imshow("Image", im);
waitKey(0);
}
The screen resolution of my monitor is 1366 x 768 maximum.
So why my program is unable to display the full uncut image?

Try this (I have done partial editing of your code, just the gutsy bits 0_0 ):
Mat im_s = imread("myimg", CV_LOAD_IMAGE_COLOR);
if (im_s.empty())
{
cout << "Cannot load image!" << endl;
return -1;
}
namedWindow( "Myimg", WINDOW_AUTOSIZE );
Size size(4096,2304);
Mat im;
resize(im_s, im, size);
imshow("Myimg", im);
waitkey(0);
return 0;

Related

C++ OpenCV 3.4 Can't find an image

#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <iostream>
using namespace cv;
int main()
{
Mat image;
image = imread("Test.jpg", IMREAD_COLOR);
if(image.empty())
{
std::cout << "Could not open or find the image" << std::endl;
return -1;
}
namedWindow("Display window", WINDOW_AUTOSIZE)
imshow("Display window", image);
waitKey(0);
}
I wrote this bit of code, but somehow it can't find the image.If I create a new image inside the "Resource Files" folder it works perfectly fine. Both images are inside the folder.
I'm using Visual Studio 2017

Grayscale video file corrupted in OpenCV3.3, MJPG codec

My setup is using a logitech c920, raspberry pi 3, and the latest opencv 3.3. I am showing in screen and writing in a file the camera stream. The only processing I am doing is converting video to grayscale. In the screen all show good, but the file is corrupted (see https://i.stack.imgur.com/QHrQb.png).
Noticeable, the video is well recorded in XVID, and also in MJPG if the original color image is selected instead.
UPDATE: I tested the same code in os-x and the same error happens, also with opencv3.3
Any advice welcome :)
This is the code:
#include "opencv2/opencv.hpp"
#include <iostream>
using namespace std;
using namespace cv;
int main() {
int FPS = 10;
int nframes;
double start, now;
VideoCapture vcap(0);
if(!vcap.isOpened()) {
cout << "Error opening video stream or file" << endl;
return 0;
}
vcap.set(CV_CAP_PROP_FOURCC,CV_FOURCC('M','J','P','G'));
int frame_width = vcap.get(CV_CAP_PROP_FRAME_WIDTH);
int frame_height = vcap.get(CV_CAP_PROP_FRAME_HEIGHT);
VideoWriter video("out.avi",CV_FOURCC('M','J','P','G'), FPS, Size(frame_width,frame_height), false);
namedWindow("Main",CV_WINDOW_AUTOSIZE); //create a window called
// Start time
start = (double)getTickCount();
for(;;) {
Mat frame, gray;
vcap >> frame;
cvtColor(frame, gray, cv::COLOR_BGR2GRAY);
video << gray;
imshow("Main", gray);
char c = (char)waitKey(2);
if( c == 27 ) break;
++nframes;
if (nframes==100) {
now = (double)getTickCount();
cout << "FPS: " << ++nframes/(now-start)*getTickFrequency() << endl;
start = now;
nframes = 0;
}
}
video.release();
return 0;
}

OpenCV: Debug Assertion Fail (pHead->nBlockUse)

My program is getting an input from the webcam and outputting the Gaussian Pyramid in real time. The program runs fine, but when I exit (by pressing a key to trigger the waitKey()), I get an error:
Debug Assertion Failed!
_BLOCK_TYPE_IS_VALID(pHead->nBlockUse))
Line 52: dbgdel.cpp
I suspect this is related to the buildPyramid() function I am using to create the Gaussian Pyramid. The output requires an Array of Mat. The number of mats that are output depends on the number of levels, so the output needs to be a pointer. I don't know if the problem is with initializing the variable or if it doesn't get deleted at the end. I could also just be completely off about the cause.
I am making the Array of Arrays with this:
std::vector<cv::Mat> GPyr;
and I am making the Gaussian Pyramid with this:
buildPyramid(imgMatNew, GPyr, levels, BORDER_DEFAULT);
Any ideas for what is causing the error?
Full Source:
#include "stdafx.h"
#include <iostream>
#include <stdio.h>
#include "opencv2/core/core.hpp"
#include "opencv2/flann/miniflann.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/photo/photo.hpp"
#include "opencv2/video/video.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/ml/ml.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/contrib/contrib.hpp"
#include "opencv2/core/core_c.h"
#include "opencv2/highgui/highgui_c.h"
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2\objdetect\objdetect.hpp"
using namespace cv;
using namespace std;
int main()
{
CvCapture* capture = 0;
// imgMatNew, imgMatOut were used to grab the current frame
Mat frame, frameCopy, image, imgMatNew, imgMatOut;
std::vector<cv::Mat> GPyr;
int levels = 4;
capture = cvCaptureFromCAM(CV_CAP_ANY); //0=default, -1=any camera, 1..99=your camera
if (!capture)
{
cout << "No camera detected" << endl;
}
//cvNamedWindow("result", CV_WINDOW_AUTOSIZE);
namedWindow("GPyrOut", WINDOW_AUTOSIZE);
namedWindow("imageNew", WINDOW_AUTOSIZE);
if (capture)
{
cout << "In capture ..." << endl;
for (;;)
{
// capture frame from video camera
IplImage* iplImg = cvQueryFrame(capture);
frame = iplImg;
// convert ilpImg into Mat format for easy processing
imgMatNew = cvarrToMat(iplImg, 1);
// Start Image Processing Here
buildPyramid(imgMatNew, GPyr, levels, BORDER_DEFAULT);
// Show Window
imshow("GPyrOut", GPyr[levels]); //show G Pyr, at a certain level, mex index = levels
imshow("imageNew", imgMatNew); //show window
if (waitKey(10) >= 0)
break;
}
// waitKey(0);
}
cvReleaseCapture(&capture);
return 0;
}
so, there's 2 things wrong here.
a) you must not use opencv's outdated c-api, mixing c and c++ calls is the straight road to hell.
b) c++ starts indexing at 0, and the last valid index is size-1, so for 4 levels, levels[4] is out of bounds. please run a debug build to get proper exceptions in this case !
here's the corrected code:
Mat frame, frameCopy, image, imgMatNew, imgMatOut;
std::vector<cv::Mat> GPyr;
int levels = 4;
VideoCapture capture(0);
if (!capture.isOpened())
{
cout << "No camera detected" << endl;
return -1;
}
//cvNamedWindow("result", CV_WINDOW_AUTOSIZE);
namedWindow("GPyrOut", WINDOW_AUTOSIZE);
namedWindow("imageNew", WINDOW_AUTOSIZE);
cout << "In capture ..." << endl;
for (;;)
{
// capture frame from video camera
capture.read(frame);
// Start Image Processing Here
buildPyramid(frame, GPyr, levels, BORDER_DEFAULT);
// Show Window
imshow("GPyrOut", GPyr[levels-1]); //show last level
imshow("imageNew", frame); //show window
if (waitKey(10) >= 0)
break;
}

See a black frame instead of a depth image with ASUS Xtion Pro and OpenCV

I can actually get a RGB image from my ASUS Xtion but cannot get any Depth image. I see a black image instead and no error shows up.
The sample SimpleView given with OpenNI works, so I guess it's not the sensor, not the library and OpenCV seems to work correctly.
Any idea?
Here is my code:
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
using namespace cv;
using namespace std;
int main( int argc, char* argv[] )
{
cout << "Device opening ..." << endl;
VideoCapture captureStream;
captureStream.open(CV_CAP_OPENNI_ASUS);
if( !captureStream.isOpened() ){
cout << "Can not open capture object." << endl;
return -1;
}
for(;;){
Mat depth;
if( !captureStream.grab() ){
cout << "ASUS Xtion can not grab images." << endl;
return -1;
}else
if( captureStream.retrieve( depth, CV_CAP_OPENNI_DEPTH_MAP) )
imshow("depth",depth);
if( waitKey( 30 ) == 27 ) break;
}
return 0;
}
Thank you!
The OpenCV sample code actually uses this code to retrieve and display the depth-map:
Mat depth;
capture.retrieve( depth, CV_CAP_OPENNI_DEPTH_MAP )
const float scaleFactor = 0.05f;
Mat show;
depth.convertTo( show, CV_8UC1, scaleFactor );
imshow( "depth map", show );

nvinitx.dll not found in Visual Studio 2012 (C++-Project)

I want to compile the following code, which seems to be valid:
#include "stdafx.h"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main( int argc, char** argv )
{
if( argc != 2)
{
cout <<" Usage: display_image ImageToLoadAndDisplay" << endl;
return -1;
}
Mat image;
image = imread(argv[1], CV_LOAD_IMAGE_COLOR); // Read the file
if(! image.data ) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl ;
return -1;
}
namedWindow( "Display window", CV_WINDOW_AUTOSIZE );// Create a window for display.
imshow( "Display window", image ); // Show our image inside it.
waitKey(0); // Wait for a keystroke in the window
return 0;
}
After that, every .dll was found, except this one: "C:\Windows\System32\nvinitx.dll". How i am able to solve this? I found out, that this .dll is the driver of my NVIDIA GeForce GTX 660M.