Ask Your Question
0

How to read pixel every frame?

asked 2015-06-29 02:53:36 -0600

bdm77 gravatar image

Hello!

I using Opencv 2.3.1 and cimg!

I need to read every frame with IP camera and record it into the BMP file.

I have the following code:

       Mat frame;
    VideoCapture cam("rtsp://admin:[email protected]/defaultPrimary?streamType=u");
    while(true)
    {   
        if (!cam.read(frame))
            continue;

        count++;
        cimg_library::CImg<unsigned char>* m_frameData = new cimg_library::CImg<unsigned char>(1920, 1080, 1 , 3);

        if (frame.data)
        {
            cvtColor(frame, frameRGB, CV_BGR2RGB);
            uchar* pixelsRGB = frameRGB.data;

            for (unsigned int x = 0; x < frame.rows; x++)               
            {
                for (unsigned int y = 0; y < frame.cols; y++)   
                {                       
                    m_frameData->atXYZC(x,y,0,0) = (int) pixelsRGB[ y + x];
                    m_frameData->atXYZC(x,y,0,1) = (int)pixelsRGB [ y + x + 1];
                    m_frameData->atXYZC(x,y,0,2) = (int) pixelsRGB[ y + x + 2];
                }
            }

            std::string fileWrite = "C:\\Temp\\out" +count+ ".bmp";             
            m_frameData->save_bmp(fileWrite.c_str());

            delete m_frameData;
     }

When I open the BMP file I get: image description

But it should be this: image description

Please help me! Thanks.

edit retag flag offensive close merge delete

Comments

3

before doing anything else, - please update your opencv . 2.3.1 is stone age, and must not be used.

berak gravatar imageberak ( 2015-06-29 03:00:32 -0600 )edit

I can't update opecv because i working in visual studio 2005.

bdm77 gravatar imagebdm77 ( 2015-06-29 03:07:06 -0600 )edit
1

can't you just imwrite() the image to bmp, without using cimg at all ? it all looks unnesserarily complicated.

berak gravatar imageberak ( 2015-06-29 03:19:25 -0600 )edit

No, because I have a lot of cameras, not all cameras work with opencv. And before writing to the disk, I must add text to image bmp.

bdm77 gravatar imagebdm77 ( 2015-06-29 03:31:58 -0600 )edit
1

I don't really understand your last comment. If you have cameras that don't work with OpenCV, then you can't use the code with them, and therefore using cimg inside the code makes no difference. Moreover, you can add text to the image before saving and still use imwrite()

LorenaGdL gravatar imageLorenaGdL ( 2015-06-29 04:05:08 -0600 )edit

This design. I have the function of receiving a frame (char*) this function adds a text in frame, and writes in the BMP file.

bdm77 gravatar imagebdm77 ( 2015-06-29 05:58:20 -0600 )edit
1

Once again, you can add text to a frame and save it as bmp file without using cimg. If we're not understanding your problem, please give more details

LorenaGdL gravatar imageLorenaGdL ( 2015-06-29 06:01:35 -0600 )edit

I can't update opecv because i working in visual studio 2005. To me that seems to be bullshit. Why would you not be able to do it? You will need to rebuild opencv yourself, but it should work just fine.

StevenPuttemans gravatar imageStevenPuttemans ( 2015-06-29 06:23:43 -0600 )edit

Once again, you can add text to a frame and save it as bmp file without using cimg. If we're not understanding your problem, please give more details.Of course I can use Opencv but then it will not match the design of the program. If it does not I will use Opencv.

bdm77 gravatar imagebdm77 ( 2015-06-29 06:56:02 -0600 )edit
1

To be honest I don't know what you're asking or what you want us to resolve, and I don't think anyone does at this point.

LorenaGdL gravatar imageLorenaGdL ( 2015-06-29 06:58:19 -0600 )edit

2 answers

Sort by ยป oldest newest most voted
0

answered 2016-04-27 07:55:30 -0600

meisam gravatar image

updated 2016-04-27 08:41:24 -0600

Hi, your pixel assigning in the loop is wrong. You read some repetitious pixels from pixelsRGB and wrote them into m_frameData pixels, in other word, pixels coordinates of pixelsRGB doesn't update properly in each loop. And you also have to alternate x and y in atXYZC. You should try this(It works for BGR format not RGB, you don't have to change the image to RGB) :

for(unsigned int x = 0; x < frame.rows; x++)
{
for (unsigned int y = 0; y < frame.cols; y++)
{

                m_frameData->atXYZC(y,x,0,0) = (int) pixelsRGB[ (3*y) + 3*x*frame.cols];
                m_frameData->atXYZC(y,x,0,1) = (int) pixelsRGB [ (3*y+1) + 3*x*frame.cols];
                m_frameData->atXYZC(y,x,0,2) = (int) pixelsRGB[ (3*y+2) + 3*x*frame.cols];

} }

I hope it works.

edit flag offensive delete link more
0

answered 2015-07-01 06:05:42 -0600

bdm77 gravatar image

updated 2015-07-01 06:06:30 -0600

This is out of Cmake:

Check for working CXX compiler using: Visual Studio 8 2005
Check for working CXX compiler using: Visual Studio 8 2005 -- works
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done
Check for working C compiler using: Visual Studio 8 2005
Check for working C compiler using: Visual Studio 8 2005 -- works
Detecting C compiler ABI info
Detecting C compiler ABI info - done
Performing Test HAVE_CXX_FSIGNED_CHAR
Performing Test HAVE_CXX_FSIGNED_CHAR - Failed
Performing Test HAVE_C_FSIGNED_CHAR
Performing Test HAVE_C_FSIGNED_CHAR - Failed
Check if the system is big endian
Searching 16 bit integer
Looking for sys/types.h
Looking for sys/types.h - found
Looking for stdint.h
Looking for stdint.h - not found
Looking for stddef.h
Looking for stddef.h - found
Check size of unsigned short
Check size of unsigned short - done
Using unsigned short
Check if the system is big endian - little endian
Looking for fseeko
Looking for fseeko - not found
Looking for unistd.h
Looking for unistd.h - not found
Check size of off64_t
Check size of off64_t - failed
Looking for assert.h
Looking for assert.h - found
Looking for fcntl.h
Looking for fcntl.h - found
Looking for io.h
Looking for io.h - found
Looking for jbg_newlen
Looking for jbg_newlen - not found
Looking for mmap
Looking for mmap - not found
Looking for search.h
Looking for search.h - found
Looking for string.h
Looking for string.h - found
Looking for unistd.h
Looking for unistd.h - not found
ICV: Removing previous unpacked package: D:/Developer/SDK/opencv/OpenCV300/sources/3rdparty/ippicv/unpack
ICV: Unpacking ippicv_windows_20141027.zip to D:/Developer/SDK/opencv/OpenCV300/sources/3rdparty/ippicv/unpack...
ICV: Package successfully downloaded
found IPP (ICV version): 8.2.1 [8.2.1]
at: D:/Developer/SDK/opencv/OpenCV300/sources/3rdparty/ippicv/unpack/ippicv_win
Could NOT find Doxygen (missing:  DOXYGEN_EXECUTABLE) 
To enable PlantUML support, set PLANTUML_JAR environment variable or pass -DPLANTUML_JAR=<filepath> option to cmake
Found PythonInterp: C:/Python27/python.exe (found suitable version "2.7.3", required is "2.7")
Found PythonLibs: C:/Python27/libs/python27.lib (Required is exact version "2.7.3")
Could NOT find PythonInterp: Found unsuitable version "2.7.3", but required is at least "3.4" (found C:/Python27/python.exe)
Could NOT find PythonInterp: Found unsuitable version "2.7.3", but required is at least "3.2" (found C:/Python27/python.exe)
Could NOT find JNI (missing:  JAVA_AWT_LIBRARY JAVA_JVM_LIBRARY JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2 JAVA_AWT_INCLUDE_PATH) 
Could NOT find Matlab (missing:  MATLAB_MEX_SCRIPT MATLAB_INCLUDE_DIRS MATLAB_ROOT_DIR MATLAB_LIBRARIES MATLAB_LIBRARY_DIRS MATLAB_MEXEXT MATLAB_ARCH MATLAB_BIN) 
VTK is not found. Please set -DVTK_DIR in CMake to VTK build directory, or to VTK install subdirectory with VTKConfig.cmake file
  videoio: Removing WinRT API headers by default

General configuration for OpenCV 3.0.0 =====================================
  Version control:               unknown

  Platform:
    Host:                        Windows 6.1 x86
    CMake:                       2.8.7
    CMake generator:             Visual Studio 8 2005
    CMake build tool:            C:/PROGRA~2/MI30EB~1/Common7/IDE/devenv.com
    MSVC:                        1400

  C/C++:
    Built as dynamic libs?:      YES
    C++ Compiler:                cl
    C++ flags (Release):         /DWIN32 /D_WINDOWS ...
(more)
edit flag offensive delete link more

Comments

I think your problem is due to /arch:SSE2 in C++ flags. Your systems simply will not yet support this. To deactivate this, there are two possibilities. You can either run CMAKE-gui inside the folder and make sure that you disable the selection of the ENABLE_SSE ENABLE_SSE2 and ENABLE_SSE3. Or you simply add it to your CMAKE command like -D ENABLE_SSE=OFF -D ENABLE_SSE2=OFF -D ENABLE_SSE3=OFF!

StevenPuttemans gravatar imageStevenPuttemans ( 2015-07-01 06:42:13 -0600 )edit

still error when compiled. .... 25>Linking... 25>LINK : fatal error LNK1104: cannot open file '....\lib\Debug\opencv_core300d.lib' 25>Build log was saved at "file://d:\Developer\SDK\opencv\OpenCV300\build\x86\vc8\apps\annotation\opencv_annotation.dir\Debug\BuildLog.htm" 25>opencv_annotation - 1 error(s), 0 warning(s) 23>cascadedetect_convert.cpp 23>..........\sources\modules\objdetect\src\hog.cpp(1412) : error C2146: syntax error : missing ')' before identifier 'signedGradient' 23>..........\sources\modules\objdetect\src\hog.cpp(1412) : error C2660: 'cv::ocl_compute' : function does not take 12 arguments 23>..........\sources\modules\objdetect\src\hog.cpp(1412) : error C2059: syntax error : ')' ......

bdm77 gravatar imagebdm77 ( 2015-07-02 01:21:09 -0600 )edit

hmm linking errors mainly occur when your installation doesnt find the OpenCV libs ... this is no compilation error ... how did you get these?

StevenPuttemans gravatar imageStevenPuttemans ( 2015-07-02 02:08:46 -0600 )edit

You can build on your computer?

bdm77 gravatar imagebdm77 ( 2015-07-02 05:19:30 -0600 )edit

I have no vs2005 around here. Why are you even using such a deprecated old compiler?

StevenPuttemans gravatar imageStevenPuttemans ( 2015-07-02 06:22:54 -0600 )edit

No answer to this question.

bdm77 gravatar imagebdm77 ( 2015-07-02 07:07:48 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-06-29 02:53:36 -0600

Seen: 1,620 times

Last updated: Apr 27 '16