I am using C920 Logitech Web camera for the object recognition project .
I want to use my own H264 decoder for decoding the compressed stream from camera (Not caring about the performance and timing as of now which will be affected by my H264 decoder).
I want to hack the bool VideoCapture::retrieve(Mat& image, int channel=0) and replace the decoder call of the opencv retrive() function by my H264 decoder .
I took care about the return type as well as parameter list of the both decoder function (BOTH ARE SIMILAR).
But I am facing below problem in integrating/modifying my sample code .
So my queries are below :
I am using OPENCV 3.0 VERSION .
Q.1) With below sample code, am getting errors-
#include "precomp.hpp"
#include "opencv2/opencv.hpp"
#include <strmif.h>
#include <iostream>
using namespace std ;
using namespace cv;
struct _AMMediaType;
typedef _AMMediaType AM_MEDIA_TYPE;
DEFINE_GUID(FORMAT_VideoInfo,0x05589f80,0xc356,0x11ce,0xbf,0x01,0x00,0xaa,0x00,0x55,0x59,0x5a);
DEFINE_GUID(MEDIATYPE_Video,0x73646976,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x38,0x9b,0x71);
DEFINE_GUID(MEDIASUBTYPE_RGB24,0xe436eb7d,0x524f,0x11ce,0x9f,0x53,0x00,0x20,0xaf,0x0b,0xa7,0x70);
int main(int, char**)
{
int t1= 10;
int t2= 10;
VideoCapture cap(0); // open the default camera
cap.set(3,1280);
cap.set(4,800);
AM_MEDIA_TYPE mt;
ZeroMemory(&mt,sizeof(AM_MEDIA_TYPE));
mt.majortype = MEDIATYPE_Video;
mt.subtype = MEDIASUBTYPE_RGB24;
mt.formattype = FORMAT_VideoInfo;
if(!cap.isOpened()) // check if we succeeded
return -1;
for(;;)
{
Mat frame;
if( !cap.grab() )
{
cout << "Can not grab images." << endl;
return -1;
}
cap.retrieve(frame);
imshow("cameracapture", frame);
if(waitKey(30) >= 0) break;
}
// the camera will be deinitialized automatically in VideoCapture destructor
return 0;
}
I am getting below linker errors :
1>main.obj : error LNK2001: unresolved external symbol FORMAT_VideoInfo
1>main.obj : error LNK2001: unresolved external symbol MEDIATYPE_Video
1>main.obj : error LNK2001: unresolved external symbol MEDIASUBTYPE_RGB24
I linked all lib in my project properties (by using VS2012),But no luck :(
Q.2) In OpenCV3.0\modules\videoio\src\cap_dshow.cpp file :
mt.majortype = MEDIATYPE_Video;
mt.subtype = MEDIASUBTYPE_RGB24;
mt.formattype = FORMAT_VideoInfo;
As my LOGITECH C920 camera is supporting H264 codec, so I tried to modify the the above variables and added below lines of code in my sample code-
mt.majortype = MEDIATYPE_Video;
mt.subtype = MEDIASUBTYPE_H264;
mt.formattype = FORMAT_VideoInfo;
I got below error :
main.obj :error C2065: 'MEDIASUBTYPE_H264' : undeclared identifier
What modifications required to get the H264 compressed video
Q-3) If I will modify the OpenCV code itself, then How I can build the complete OPENCV3.0 code(with my modification in windows with VS2012) and use it for my purpose ??
You need to define INITGUID to resolve mentioned linker errors (see Referencing GUIDs for details).
However I don't see how it is going to help you in the part of supplying your H.264 decoder (too far from there).
To reference H.264 subtype identifier you need
#include <wmcodecdsp.h>
#pragma comment(lib, "wmcodecdspuuid.lib")
Related
I have a problem : error LNK2019: unresolved external symbol [...] referenced in function main
#include <opencv2/highgui/highgui.hpp>
using namespace std;
using namespace cv;
int main(int argc, char * const argv[])
{
cvNamedWindow("P2", CV_WINDOW_AUTOSIZE);
//path to image ex : c:/Users/image.jpg
CvCapture* capture = cvCreateFileCapture("path to image");
IplImage* frame;
while (1) {
frame = cvQueryFrame(capture);
if (!frame) break; cvShowImage("P2", frame); char c = cvWaitKey(0); if (c == 27) break;
}
cvReleaseCapture(&capture); cvDestroyWindow("P2");
return 0;
}
enter image description here
I start my project by following tutorial, the same configuration to use OpenCV with visual Studio and Eclipse but I have the same error.
Probably you're missing to specify input library (project property/link/input).
You don't specify which version of opencv you are using. If you are using openCV 3.1 like me the lib is opencv_world310d.lib for debug and opencv_world310.lib for release. Please check also the bitness of your application. The prebuilt libraries are for 64 bit.
I was trying to encode an image using WIC.
and i made simple dll (to encode/decode) and reffered it from another aplication.
I added my_bitmap_converter() to do a convertion intended to use WICConvertBitmapSource() but it gives me a link error. here is my work
int my_bitmap_converter
(
REFWICPixelFormatGUID dstPixelFormt,
IWICBitmapSource* piBitmapSource,
IWICBitmapSource** ppiBitmapDst
)
{
IWICBitmapSource* piScr = piBitmapSource;
IWICBitmapSource** ppiDst = ppiBitmapDst;
hr = WICConvertBitmapSource
(
dstPixelFormt,//GUID_WICPixelFormat128bppPRGBAFloat,
piScr,
ppiDst
);
if (SUCCEEDED(hr))
{
piScr->Release();
return 0;
}
return -1;
}
how can i get rid of this error
Error 1 error LNK2019: unresolved external symbol
_WICConvertBitmapSource#12 referenced in function "int __cdecl my_bitmap_converter(struct _GUID const &,struct IWICBitmapSource
*,struct IWICBitmapSource * *)" (?my_bitmap_converter##YAHABU_GUID##PAUIWICBitmapSource##PAPAU2##Z)
---wincodec.h---
HRESULT WINAPI WICConvertBitmapSource(
_In_ REFWICPixelFormatGUID dstFormat, // Destination pixel format
_In_reads_(1) IWICBitmapSource *pISrc, // Source bitmap
_Outptr_result_buffer_(1) IWICBitmapSource **ppIDst // Destination bitmap, a copy or addrefed source
);
if you referred here, you may realize that "Link library name is "windowscodecs.lib" instead of "wincodec.lib" in Windows SDK 7.0 "
maybe you are using SDK 7.0 or later. if it is, try adding windowscodecs.lib as an additional dependencies.
I am trying to use graph library using opencv.
This is the code that I have written , and am building this on Visual studio 2010.
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include "GraphUtils.h"
using namespace cv;
using namespace std;
int main()
{
float floatArray[4]= {1,1,2,2};
showFloatGraph("Rotation Angle", floatArray, 4 );
return 0;
}
There is no compilation error.
However, I am getting following linking error:
Error 1 error LNK2019: unresolved external symbol _showFloatGraph
referenced in function _main C:\Users\Yam\Documents\Visual Studio
2010\Projects\plot\opencv1\helloworld.obj
Error 2 error LNK1120: 1 unresolved externals C:\Users\Yam\Documents\Visual Studio
2010\Projects\plot\Debug\opencv1.exe
I have put the two files (GraphUtils.h and GraphUtils.c) with my .cpp file.
Why I am getting these compilation errors whenever I am using third party libraries (.c and .h) files, since I get this linking error also when using other library. I asked the question here
In Properties=>Linker=>input=>Additional dependencies , I have added :
opencv_core231d.lib;opencv_highgui231d.lib;opencv_imgproc231d.lib;opencv_features2d231d.lib;opencv_calib3d231d.lib;%(AdditionalDependencies)
And in fact my basic opencv program for image display works fine.
Do I need to do something special when using these libraries. As of now I just copy paste the .c and .h files in the folder where my .cpp file is present. Do I need to do something more ?
Update:
I found that the the file GraphUtils.c has the following code:
// OpenCV
#include <cv.h>
#include <cxcore.h>
#ifdef USE_HIGHGUI
#include <highgui.h>
#endif
I found that the cv.h, cxcore.h and highgui.h are actually present in opencv 2.3.1/opencv folder and so I changed it like this:
#include <opencv/cv.h>
#include <opencv/cxcore.h>
#ifdef USE_HIGHGUI
#include <opencv/highgui.h>
#endif
Unfortunately this gave rise to more linking errors.
Update
The following program works fine.
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
#include<conio.h>
using namespace cv;
using namespace std;
int main( int argc, const char** argv )
{
Mat img = imread("xyz.bmp", CV_LOAD_IMAGE_UNCHANGED); //read the image data in the file "MyPic.JPG" and store it in 'img'
if (img.empty()) //check whether the image is loaded or not
{
cout << "Error : Image cannot be loaded..!!" << endl;
//system("pause"); //wait for a key press
return -1;
}
namedWindow("MyWindow", CV_WINDOW_AUTOSIZE); //create a window with the name "MyWindow"
imshow("MyWindow", img); //display the image which is stored in the 'img' in the "MyWindow" window
waitKey(0); //wait infinite time for a keypress
destroyWindow("MyWindow"); //destroy the window with the name, "MyWindow"
getch();
return 0;
}
But this program always gives error; no header file recognized. so no function would work:
#include "cv.h" //main OpenCV header
#include "highgui.h" //GUI header
int main() {
// declare a new IplImage pointer
IplImage* myimage;
// load an image
myimage = cvLoadImage("sayyidsmile.jpg",1); //change the file name with your own image
//create a new window & display the image
cvNamedWindow("Smile", 1);
cvMoveWindow("Smile", 100, 100);
cvShowImage("Smile", myimage);
//wait for key to close the window
cvWaitKey(0);
cvDestroyWindow( "Smile" );
cvReleaseImage( &myimage );
return 0;
}
Details on Env. Variables
I followed this article to set EVs.
Currently my variables are like this:
Name Value
OpenCV: C:\Users\Yuvue\Desktop\OpenCV2.3.1
INCLUDE: %OPENCV%\build\include
LIB: %OPENCV%\build\x86\vc10\lib
Path: %OPENCV%\build\x86\vc10\bin
Under Properties => VC++ Directories=> Library Directories, I have added the following:
$(OPENCV)\build\x86\vc10\lib
The second program compiles when I explicitly gives path of cv.h in the include. But if I do so with any of the third party libraries when they have used #include, it starts giving linking error (my original question).
Please help me sort this!!
I am really new to Opencv. After downloading and installing Opencv 2.4 according to the instruction, I began writing my first Opencv program, which was basically a copy of the tutorial on the web.
#include <stdio.h>
#include <iostream>
#include <vector>
#include "cv.h"
#include "highgui.h"
#include <stdio.h>
#include <stdlib.h>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main( int argc, char** argv )
{
char* filename = "C:\\Research\abc.pgm";
IplImage *img0;
if( (img0 = cvLoadImage(filename,-1)) == 0 )
return 0;
cvNamedWindow( "image", 0 );
cvShowImage( "image", img0 );
cvWaitKey(0);
cvDestroyWindow("image");
cvReleaseImage(&img0);
return 0;
}
The codes work very well, but you may notice that in the above code invoking Opencv function is in a C code fashion. I therefore decide to proceed with C++ code fashion with the following codes:
#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;
}
However, in this case the program has several link errors although compiling seems fine. The link errors I have received are as follows:
Error 2 error LNK2019: unresolved external symbol "void __cdecl cv::namedWindow(class stlp_std::basic_string<char,class stlp_std::char_traits<char>,class stlp_std::allocator<char> > const &,int)" (?namedWindow#cv##YAXABV?$basic_string#DV?$char_traits#D#stlp_std##V?$allocator#D#2##stlp_std##H#Z) referenced in function _main C:\Research\OpencvTest\OpencvTest.obj
Error 1 error LNK2019: unresolved external symbol "void __cdecl cv::imshow(class stlp_std::basic_string<char,class stlp_std::char_traits<char>,class stlp_std::allocator<char> > const &,class cv::_InputArray const &)" (?imshow#cv##YAXABV?$basic_string#DV?$char_traits#D#stlp_std##V?$allocator#D#2##stlp_std##ABV_InputArray#1##Z) referenced in function _main C:\Research\OpencvTest\OpencvTest.obj
I am quite sure that I have added necessary Opencv libraries in my program (I use VC10), and the additional libraries I have added are as follows:
stl_port.lib
opencv_highgui242d.lib
opencv_core242d.lib
I was wondering what's wrong with my setting. Why does it work for the first program but not the second one? Any ideas will be appreciated. Thanks!
It has something to do with mixing STLPort and MSVC STL. You probably didn't build OpenCV libraries yourself, so they're using VC10 STL. With C interface there's just char* but with C++ interface linker gets confused with std::string in methods. You should see the same result with imread if you cast it's input to string too.
Can I mix STL implementations in my project?
I'm trying to get this accurate timer working on VS2008, on Windows XP (and eventually Server 2008) from the following example:
http://technology.chtsai.org/w98timer/
However I get the following errors:
error LNK2019: unresolved external symbol _imp_timeEndPeriod#4
error LNK2019: unresolved external symbol _imp_timeGetTime#0
error LNK2019: unresolved external symbol _imp_timeBeginPeriod#4
error LNK2019: unresolved external symbol _imp_timeGetDevCaps#8
Could anybody please advise?
I just want a simple, accurate, millisecond-timing example for C++ on Windows.
#include <stdio.h>
#include <windows.h>
#include <mmsystem.h>
#include "stdafx.h"
void
main (void)
{
TIMECAPS resolution;
DWORD start, finish, duration, i;
if (timeGetDevCaps (&resolution, sizeof (TIMECAPS)) == TIMERR_NOERROR)
{
printf ("Minimum supported resolution = %d\n", resolution.wPeriodMin);
printf ("Maximum supported resolution = %d\n", resolution.wPeriodMax);
}
if (resolution.wPeriodMin <= 1)
{
if (timeBeginPeriod (1) == TIMERR_NOERROR)
{
for (i = 100; i <= 120; i++)
{
start = timeGetTime ();
while (timeGetTime () < (start + i));
finish = timeGetTime ();
duration = finish - start;
printf ("expected:%d actual:%ld\n", i, duration);
}
timeEndPeriod (1);
}
}
}
As MSDN suggests you need to include winmm.lib into the project. So add the following line anywhere into your source code:
#pragma comment(lib, "winmm.lib")
Looking at the docs it looks like you need to add Winmm.lib to the additional libraries to link in your project properties.
You need to add winmm.lib to your linker dependencies.
These functions are defined in winmm.dll. You need to add winmm.lib to your link list.