Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8528889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:54:13+00:00 2026-06-11T08:54:13+00:00

Good day everyone! So currently I’m working on a project with video processing, so

  • 0

Good day everyone! So currently I’m working on a project with video processing, so I decided to give a try to OpenCV. As I’m new to it, I decided to find few sample codes and test them out. First one, is C OpenCV and looks like this:

#include <opencv/cv.h>
#include <opencv/highgui.h>

#include <stdio.h>

int main( void ) {

CvCapture* capture = 0;
IplImage *frame = 0;

    if (!(capture = cvCaptureFromCAM(0)))
    printf("Cannot initialize camera\n");

cvNamedWindow("Capture", CV_WINDOW_AUTOSIZE);

while (1) {

    frame = cvQueryFrame(capture);
    if (!frame)
        break;

    IplImage *temp = cvCreateImage(cvSize(frame->width/2, frame->height/2), frame->depth, frame->nChannels); // A new Image half size

    cvResize(frame, temp, CV_INTER_CUBIC); // Resize
    cvSaveImage("test.jpg", temp, 0); // Save this image
    cvShowImage("Capture", frame); // Display the frame
    cvReleaseImage(&temp);
    if (cvWaitKey(5000) == 27) // Escape key and wait, 5 sec per capture
        break;
}

cvReleaseImage(&frame);
cvReleaseCapture(&capture);

return 0;

}

So, this one works perfectly well and stores image to hard drive nicely. But problems begin with next sample, which uses C++ OpenCV:

#include "opencv2/opencv.hpp"
#include <string>

using namespace cv;

int main(int, char**)
{
    VideoCapture cap(0); // open the default camera
    if(!cap.isOpened())  // check if we succeeded
        return -1;

    Mat edges;
    //namedWindow("edges",1);
    for(;;)
    {
        Mat frame;
        cap >> frame; // get a new frame from camera
        cvtColor(frame, edges, CV_RGB2XYZ);
        imshow("edges", edges);
    //imshow("edges2", frame);
    //imwrite("test1.jpg", frame);
        if(waitKey(1000) >= 0) break;
    }
    // the camera will be deinitialized automatically in VideoCapture destructor
    return 0;
}

So, yeah, generally, in terms of showing video (image frames) there is practically no changes, but when it comes to using im** functions, some problems arise.

Using cvSaveImage() works out nicely, but the moment I try to use imwrite(), unhandled exception arises in regards of ‘access violation reading location’. Same goes for imread(), when I’m trying to load image.

So, the thing I wanted to ask, is it possible to use most of the functionality with C OpenCV? Or is it necessary to use C++ OpenCV. If yes, is there any solution for the problem I described earlier.


Also as stated here, images initially are in BGR-format, so conversion needed. But doing BGR2XYZ conversion seems to invert colors, while RGB2XYZ preserve them. Examples:

images

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T08:54:14+00:00Added an answer on June 11, 2026 at 8:54 am

    Or is it necessary to use C++ OpenCV?

    No, there is no necessity whatsoever. You can use any interface you like and you think you are good with it (OpenCV offers C, C++, Python interfaces).

    For your problem about imwrite() and imread() :

    For color images the order channel is normally Blue, Green, Red , this
    is what imshow() , imread() and imwrite() expect

    Quoted from there

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good day everyone. I am working on a Firefox extension, and I want to
Good day everyone. I am creating a calendar component, and I'm working in the
Good day for everyone. I have a strange error working with mongoose module.js:437 var
Good day everyone, I'm new in C programming and I don't have a lot
Good Day Everyone... Apparently, I'm not setting-up impersonation correctly for my WCF service. I
Good day everyone, I'm an independent game developer who has, in the past, primarily
Good day everyone, I am building a page in ASP.NET, and using Master Pages
Good Day Everyone... I’m getting an unexpected WCF error complaining of Known Types which
Good day everyone. I have been having the same problem all day at work
Good day everyone! I have a problem regarding my date. It needs to be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.