#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
int main()
{
cv::Mat im =cv::imread("C:/OpenCV2.3/opencv/samples/cpp/matching_to_many_images/query.png");
if(im.empty())
{
return -1;
}
cv::namedWindow("image", CV_WINDOW_AUTOSIZE);
cv::imshow("image" , im);
cv::waitKey();
return 0;
}
After executing this code sample , i have gray window. Whean i move a cursor on the window, it shows , that something is loading. What's the problem? I'am sure that the imagepath is correct.
I had the same error. Turned out my system missed the msvcp100d.dll and msvcr100d.dll files.
Related
I have used opencv and c++ to remove watermark from image using code below.
#include <stdio.h>
#include <opencv2/opencv.hpp>
#include <Windows.h>
#include <string>
#include <filesystem>
namespace fs = std::filesystem;
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
bool debugFlag = true;
std::string path = "C:/test/";
for (const auto& entry : fs::directory_iterator(path))
{
std::string fileName = entry.path().string();
Mat original = imread(fileName, cv::IMREAD_COLOR);
if (debugFlag) { imshow("original", original); }
Mat inverted;
bitwise_not(original, inverted);
std::vector<Mat> channels;
split(inverted, channels);
for (int i = 0; i < 3; i++)
{
if (debugFlag) { imshow("chan" + std::to_string(i), channels[i]); }
}
Mat bwImg;
cv::threshold(channels[2], bwImg, 50, 255, cv::THRESH_BINARY);
if (debugFlag) { imshow("thresh", bwImg); }
Mat outputImg;
inverted.copyTo(outputImg, bwImg);
bitwise_not(outputImg, outputImg);
if (debugFlag) { imshow("output", outputImg); }
if (debugFlag) { waitKey(0); }
else { imwrite(fileName, outputImg); }
}
}
here is result original to removed watermark.
Now in previous image as you can see original image has orange/red watermark. I created a mask that would kill the watermark and then applied it to the original image (this pulls the grey text boundary as well). Another trick that helped was to use the red channel since the watermark is most saturated on red ~245). Note that this requires opencv and c++17
But now i want to remove watermark in new image which has similar watermark color as text image is given below as you can see some watermark in image sideway in chinese overlaping with text. how to achieve it with my current code any help is appreciated.
Two ideas to try:
1: The watermark looks "lighter" than the primary text. So if you create a grayscale version of the image, you may be able to apply a threshold that keeps the primary text and drops the watermark. You may want to add one pass of dilation on that mask before applying it to the original image as the grey thresh will likely clip your non-watermark characters a bit. (this may pull in too much noise from the watermark though, so test it)
2: Try using the opencv opening function. Your primary text seems thicker than the watermark, so you should be able to isolate it. Similarly after you create the mask of your keep text, dilate once and mask the original image.
I was using my acer crystal eye camera until now. It was giving me the exact output as I need but when I moved into using my Logitech camera it gives me just a black window.
Nothing is wrong with my Logitech camera I am using it for skyping and even I tried the onlinemirror as well.
Can anybody help me. there were lot of solutions for this issue but nothing helped me.
#include <stdio.h>
#include <stdlib.h>
#include <cv.h>
#include <highgui.h>
int main(int argc, char** argv) {
CvCapture *video = cvCaptureFromCAM(1);
IplImage * img = NULL
if(!cvGrabFrame(video)){
printf("could not grab a frame\n");
exit(0);
}
cvNamedWindow("original_image",0);
while(1){
img = cvQueryFrame(video);
cvShowImage("original_image",img);
if (cvWaitKey(0)==27){
break;
}
cvReleaseImage(&img);
cvReleaseCapture(&video);
return (EXIT_SUCCESS);
}
Try to use if (cvWaitKey(30)==27) works instead of if (cvWaitKey(0)==27)
The highgui needs some time to update the frame.
Are you sure that your usb camera has index 1?
CvCapture *video = cvCaptureFromCAM(1);
You could try to disable your acer webcam in the Device Manager (if you are using windows) and then replace the above line with:
CvCapture *video = cvCaptureFromCAM(CV_CAP_ANY);
This way, you make sure you only have 1 camera enabled(the usb camera), and by using CV_CAP_ANY you make sure that that one cam is used. If this still gives you a black/blank screen, you know something else is wrong.
Here is a link to the type of images my program produces: http://imgur.com/a/vibBx#0
I am trying out a simple capture test program that I have written. I am trying to capture images in a loop and save them onto the board properly numbered. The first capture sometimes is corrupted and the subsequent captures are a mix of two images. I have also observed that sometimes the upper half of the image is from the previous capture and the lower half is the capture from that cycle. I have given the details and the code below.
OpenCV 2.4.2 running on BeagleBone Black which has Ångström installed on it.
The camera which is plugged to the USB of BeagleBone Black is Logitech C920.
The camera is connected to BeagleBone Black before power up through the 5 V power supply and connecting BeagleBone Black to the laptop. Access is through PuTTY.
Code
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <iostream>
#include <string>
#include <unistd.h>
#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <cxcore.h>
#include "LaserWeed.h"
#include "SimpleGPIO.h"
using namespace cv;
int main(int argc, char* argv[])
{
int i=0, a;
string name;
int length;
char c, Filename[10000];
CvCapture* capture = NULL;
IplImage* img = NULL;
do
{
//I am not sure if this is necessary, but I tried anyway
//to see if it makes a difference since upper half of
//image was from previous cycle.
capture = NULL;
img = NULL;
//Converting Numbers to string to save with proper name
std::stringstream ss;
ss << i;
name = ss.str();
name = name + ".jpg";
length = name.size();
for(a=0; a<length; a++)
{
Filename[a] = name[a];
}
capture = cvCaptureFromCAM(-1);
if (!capture)
{
fprintf( stderr, "ERROR: capture is NULL \n" );
getchar();
return -1;
}
img = cvQueryFrame(capture);
if (!img)
{
fprintf(stderr, "ERROR: img is null...\n");
getchar();
return -1;
}
cvSaveImage(Filename,img);
cvReleaseCapture(&capture);
cvReleaseImage(&img);
i++;
c = getchar();
}
while (c!='e')
;
return 0;
}
Where might I be going wrong?
The Stack Overflow question BeagleBone, OpenCV and webcam issue somewhat has a similar problem. But reinstallation of the OS will be my last option.
This is weird, anyway try to take the capture out of the do-while loop, maybe opening and releasing the capture device each time won't give enough time for the camera to prepare it's image buffers.
I am trying to read an AVI file using openCV. After getting the capture, the problem comes when I give a condition to the while loop which governs the extent to which queryFrame will be done.
There are total 1251 frames in the video.
When I use while (counter <= number_of_frames), the video runs fine and,
when I use while (cvQueryFrame(capture)), the video runs fine till 200-250th frame, then suddenly it starts running faster and finishes by 625th frame. I printed the FPS, it remains same all the time.
Why is this happening ??
Please help!
try the following...
C style reading..
#include <opencv2/video/video.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace cv;
int main()
{
CvCapture *video;
video = cvCreateFileCapture("ADDRESS TO THE FILE");
IplImage *frame;
while(true)
{
frame = cvQueryFrame(video);
if(frame->imageData==NULL)
{
std::cout<<"END OF VIDEO"<<std::endl;
break;
}
cvShowImage("VIDEO",frame);
cvWiatKey(25);//SINCE MOST OF THE VIDEOS RUN AT 25 FPS
}
return 0;
}
C++ STYLE....
int main()
{
VideoCapture video("ADDRESS OF VIDEO");
Mat frame;
while(true)
{
video >> frame;
if(frame.data==NULL)
{
std::cout<<"END OF VIDEO FILE"<<std::endl;
break;
}
imshow("VIDEO",frame);
waitKey(25);
}
return 0;
}
try this...and check if it gives an uniform rate of play...
I am using opencv 2.3.1a in ubuntu 11.o4.
I installed opencv using: http://www.samontab.com/web/2011/06/installing-opencv-2-2-in-ubuntu-11-04/
Since I could not use webcam with that installation. I changed "cmake" option from WITH_V4L=OFF to WITH_V4L=ON. But it still does not work.
I tried the following code:
#include "cv.h"
#include "highgui.h"
#include <stdio.h>
// A Simple Camera Capture Framework
int main() {
CvCapture* capture = cvCaptureFromCAM( 0);
if(!capture)
{
printf("no camera");
return -1;
}
}
And yeah the output is : no camera
I do not know where the problem is.
I followed the steps mentioned in:
http://www.ozbotz.org/opencv-installation/
This solved the problem.