Ask Your Question

zulfiqar's profile - activity

2019-11-27 12:19:02 -0600 received badge  Popular Question (source)
2019-10-31 08:37:25 -0600 received badge  Notable Question (source)
2018-07-12 06:17:07 -0600 received badge  Notable Question (source)
2018-07-08 13:53:26 -0600 received badge  Popular Question (source)
2017-09-27 02:08:49 -0600 received badge  Popular Question (source)
2017-03-22 06:20:44 -0600 received badge  Popular Question (source)
2016-11-06 02:36:06 -0600 received badge  Notable Question (source)
2016-10-31 20:41:52 -0600 received badge  Popular Question (source)
2016-04-26 13:52:30 -0600 received badge  Popular Question (source)
2015-07-04 00:28:21 -0600 received badge  Famous Question (source)
2014-12-09 14:00:19 -0600 marked best answer mutiply scalar to a vector opencv

I want to mutiply 2 with each element of vec3 in opencv as we do in Matlab simplt by ".*". I searched alot but didn't find any command is their any command for this or not in opencv? thanks in advance for any help

2014-12-09 13:59:03 -0600 marked best answer make black image in opencv using Iplimage of user specified dimensions

I am new to opencv. I want to make a black image of user specified dimensions . I have found this

Mat atom_image = Mat::zeros( w, w, CV_8UC3 );

for Mat but i want to use IplImage * . Is there any method similar to the above for IplImage . Thanks for any help.

2014-12-09 13:58:27 -0600 marked best answer convert string^ to char* windows form application c++

i m reading path from textbox and then tried to open image

String^ P = path->Text;

IplImage* img = cvLoadImage(P);

It gives me the following error Error 1 error C2664: 'cvLoadImage' : cannot convert parameter 1 from 'System::String ^' to 'const char *'

Can anyone tell me how to convert it to char *.

2014-12-09 13:58:25 -0600 marked best answer Unable to link opencv to windows form application

i have linked opencv to console application but when i tried to link it to windows form application VS 2010 it gives me following errors

Error   1   error C2065: 'IplImage' : undeclared identifier c:\users\ayesha\documents\visual studio 2010\projects\abc\abc\Form1.h   130 1   abc
Error   2   error C3861: 'cvLoadImage': identifier not found    c:\users\ayesha\documents\visual studio 2010\projects\abc\abc\Form1.h   130 1   abc

#pragma once
#include "highgui.h"
#include <opencv2/imgproc/imgproc.hpp>  // Gaussian Blur
#include <opencv2/core/core.hpp>        // Basic OpenCV structures (cv::Mat, Scalar)
#include <opencv2/highgui/highgui.hpp>

namespace abc {

    using namespace System;
    using namespace System::ComponentModel;
    using namespace System::Collections;
    using namespace System::Windows::Forms;
    using namespace System::Data;
    using namespace System::Drawing;
    using namespace System::IO;


    /// <summary>
    /// Summary for Form1
    /// </summary>
    public ref class Form1 : public System::Windows::Forms::Form
    {
    public:
        Form1(void)
        {
            InitializeComponent();
            //
            //TODO: Add the constructor code here
            //
        }

        protected:
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        ~Form1()
        {
            if (components)
            {
                delete components;
            }
        }
        private: System::Windows::Forms::Button^  button1;
    private: System::Windows::Forms::TextBox^  path;
    private: System::Windows::Forms::Button^  summary;
    protected: 


        private:
        /// <summary>
        /// Required designer variable.
        /// </summary>
        System::ComponentModel::Container ^components;

        #pragma region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        void InitializeComponent(void)
        {
            this->button1 = (gcnew System::Windows::Forms::Button());
            this->path = (gcnew System::Windows::Forms::TextBox());
            this->summary = (gcnew System::Windows::Forms::Button());
            this->SuspendLayout();
            // 
            // button1
            // 
            this->button1->Location = System::Drawing::Point(392, 68);
            this->button1->Name = L"button1";
            this->button1->Size = System::Drawing::Size(75, 23);
            this->button1->TabIndex = 0;
            this->button1->Text = L"browse";
            this->button1->UseVisualStyleBackColor = true;
            this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
            // 
            // path
            // 
            this->path->Location = System::Drawing::Point(23, 68);
            this->path->Name = L"path";
            this->path->Size = System::Drawing::Size(304, 20);
            this->path->TabIndex = 1;
            // 
            // summary
            // 
            this->summary->Location = System::Drawing::Point(153, 156);
            this->summary->Name = L"summary";
            this->summary->Size = System::Drawing::Size(159, 27);
            this->summary->TabIndex = 2;
            this->summary->Text = L"summaize video";
            this->summary->UseVisualStyleBackColor = true;
            this->summary->Click += gcnew System::EventHandler(this, &Form1::summary_Click);
            // 
            // Form1
            // 
            this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->ClientSize = System::Drawing::Size(568, 262);
            this->Controls->Add(this->summary);
            this->Controls->Add(this->path);
            this->Controls->Add(this->button1);
            this->Name = L"Form1";
            this->Text = L"Form1";
            this->ResumeLayout(false);
            this->PerformLayout();

        }
#pragma endregion
    private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
        Stream^ myStream;
        OpenFileDialog^ openFileDialog1 = gcnew OpenFileDialog;

        openFileDialog1->InitialDirectory = "c:\\";
        openFileDialog1->Filter = "txt files (*.avi)|*.avi|All files (*.*)|*.*";
        openFileDialog1->FilterIndex = 2;
        openFileDialog1->RestoreDirectory = true;

        if ( openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK )
        {
            if ( (myStream = openFileDialog1->OpenFile()) != nullptr )
            {
                path->Text = Convert::ToString(openFileDialog1->FileName);

                // Insert code to read the stream here.
                String ^ temp = "you have successfully browsed a video";
                System::Windows::Forms::MessageBox::Show(temp);

                myStream->Close();
            }
        }
    }
private: System::Void summary_Click(System::Object^  sender, System::EventArgs^  e) {
            // Set ...
(more)
2014-12-09 13:55:53 -0600 marked best answer Fatal error while converting image from rgb to gray

I am new to opencv . I am using cv::cvtColor(frame,frame,CV_BGR2GRAY); to convert rgb frame to gray but it gives linking error. All other basic functions eg reading and writing images and videos are working perfectly . Please help me which library I have to add

2014-12-09 13:42:17 -0600 marked best answer Displaying video using vector<Mat> not working proplerly

I am trying to display video for in a separate function for this i am using vector<mat> i push_back each frame in and then pass this vector to function but my function displays a single frame repetitively. My code is below. Please tell me what i am doing wrong. // newproject.cpp : Defines the entry point for the console application.

#include "stdafx.h"
#include "highgui.h"
#include <stdio.h>
#include <cv.h>
#include <highgui.h>
#include <stdio.h>
#include <conio.h>
#include <opencv2/imgproc/imgproc.hpp>  // Gaussian Blur
#include <opencv2/core/core.hpp>        // Basic OpenCV structures (cv::Mat, Scalar)
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <conio.h>

using namespace cv;
using namespace std;

class frameprocessing{

Mat hsv_base;
MatND hist_base;

public:
    void hsv_histogram(Mat Frame)
    {
        cvtColor( Frame, hsv_base, CV_BGR2HSV );
        int h_bins = 50; 
        int s_bins = 32;
        int histSize[] = { h_bins, s_bins };

        float h_ranges[] = { 0, 256 };
        float s_ranges[] = { 0, 180 };

        const float* ranges[] = { h_ranges, s_ranges };
        int channels[] = { 0, 1 };
        calcHist( &hsv_base, 1, channels, Mat(), hist_base, 2, histSize, ranges, true, false );
    }
};

class video{    

    Mat frame;
    string filename;
    double dWidth;
    double dHeight;

public:
    video()
    {

    }

    video(string videoname)
    {

        vector<Mat> videoframes;
        std::vector<Mat>::iterator it;
        it = videoframes.begin();
        filename = videoname;
        VideoCapture capture(filename); 
        if( !capture.isOpened() )
        {
            exit(0);
        }
        dWidth   = capture.get(CV_CAP_PROP_FRAME_WIDTH); //get the width of frames of the video
        dHeight = capture.get(CV_CAP_PROP_FRAME_HEIGHT); //get the height of frames of the video

        frameprocessing obj;

        for( ; ; )
        {
            capture >> frame;
            if(frame.empty())
                break;

            obj.hsv_histogram(frame);
            videoframes.push_back(frame);
        }
        displayvideo(videoframes);
    //  waitKey(0); // key press to close window
    }

    void writer()
    {
        Size frameSize(static_cast<int>(dWidth), static_cast<int>(dHeight));
        VideoWriter oVideoWriter ("D:/MyVideo.avi", CV_FOURCC('P','I','M','1'), 20, frameSize, true); //initialize the VideoWriter object 
        if ( !oVideoWriter.isOpened() ) //if not initialize the VideoWriter successfully, exit the program
        {
            cout << "ERROR: Failed to write the video" << endl;
            exit(0);
        }
    }
    void displayvideo(vector<Mat> videoframe)
    {
        Mat tempframe;
        while(!videoframe.empty()) //Show the image captured in the window and repeat
        {
            tempframe = videoframe.back();
            imshow("video", tempframe);
            videoframe.pop_back();
            waitKey(20); // waits to display frame
        }
    //  waitKey(0);
    }

};

int _tmain(int argc, _TCHAR* argv[])
{
    video obj("video.avi");
    //obj.readvideo();
}
2014-10-08 12:01:35 -0600 received badge  Notable Question (source)
2014-08-24 09:11:22 -0600 received badge  Popular Question (source)
2014-06-12 07:43:48 -0600 received badge  Popular Question (source)
2014-03-14 13:23:00 -0600 asked a question QT creator No such slot found

I am trying to make a simple GUI but on click it displays no such slot interface::browsefile(). Interface::Interface(QWidget *parent) :QMainWindow(parent),ui(new Ui::Interface) { ui->setupUi(this); connect(this->ui->pushButton, SIGNAL(clicked()), this, SLOT(browsefile())); }

        Interface::~Interface()
        {
           delete ui;
         }
       void Interface::browsefile()
       {
             this->ui->lineEdit->setText("Hello");

       }
2014-03-13 01:02:40 -0600 asked a question confidence level of face detection in haar cascade

I want to find confidence level of face detected in haar cascade is there any method to find the confidence of each face detected in opencv c++.

2014-03-06 03:05:57 -0600 marked best answer display many images in single window in opencv

I am new to opencv. I want to display many images in a single window currently i m showing each image in new window and old window get destroyed.I don't know number of images before hand. below is my code

 // newproject.cpp : Defines the entry point for the console application.

#include "stdafx.h"
#include "highgui.h"
#include <stdio.h>
#include <cv.h>
#include <highgui.h>
#include <stdio.h>
#include <conio.h>
#include <opencv2/imgproc/imgproc.hpp>  // Gaussian Blur
#include <opencv2/core/core.hpp>        // Basic OpenCV structures (cv::Mat, Scalar)
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <conio.h>

using namespace cv;
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
//Image Reading
IplImage* img = cvLoadImage( "index.jpg" );
cvNamedWindow( "Example1", CV_WINDOW_AUTOSIZE );
cvShowImage( "Example1", img );
cvWaitKey(0);
cvDestroyWindow( "Example1" );
cout<<img->height<<endl;
cout<<img->width<<endl;

//Summarize by sampling

CvCapture* capture = 0;
capture = cvCreateFileCapture( "video.avi" );
if(!capture){
    return -1;
}
IplImage *bgr_frame=cvQueryFrame(capture);//Init the video read
double fps = cvGetCaptureProperty (capture,CV_CAP_PROP_FPS);
CvSize size = cvSize((int)cvGetCaptureProperty( capture, CV_CAP_PROP_FRAME_WIDTH),(int)cvGetCaptureProperty( capture, CV_CAP_PROP_FRAME_HEIGHT));
CvVideoWriter *writer = cvCreateVideoWriter("ayesh.avi",-1,10,size);
IplImage* logpolar_frame = cvCreateImage(size,IPL_DEPTH_8U,3);

cout<<size.height<<endl;
cout<<size.width<<endl;

int x=0;
while(1){       

    x++;
    bgr_frame = cvQueryFrame( capture );
    if(!bgr_frame)
        break;

    if(x==19||x==21||x==18||x==17||x==22){
        cvShowImage("Example2",bgr_frame);
        cvWriteFrame( writer, bgr_frame );
    }

    if(x==20){
        cvShowImage("Example2",bgr_frame);
        cvShowImage ("Example2",img);
        cvWriteFrame( writer, bgr_frame );
        cvWriteFrame( writer , img);
        x=0;
    }
}

cvReleaseVideoWriter( &writer );
cvReleaseCapture( &capture );
cvDestroyWindow( "Example2" );
}
2014-03-03 05:41:50 -0600 asked a question method for shot dtection from a video in opencv, c++

Is there any method for detecting shot from a video in opencv? I have done a lot of searching but didn't find any. can anyone can give any link for shot detection using opencv, c++? I need it for doing a project. Thanks for any help :)

2014-02-11 08:43:34 -0600 asked a question show many images in different windows in a loop using one imshow command

I want to show many images in different windows in a loop. I am currently doing this

 for (int i=0; i<keyframesbuffer.size(); i++)
 {
    imshow("Keyframe",keyframesbuffer[i]);
    cv::waitKey(60);

 }

but it creates a single window . can anyone please tell me how to make multiple windows in a loop. thanks for any help.

2014-02-07 01:04:19 -0600 received badge  Student (source)
2014-01-01 09:46:16 -0600 asked a question face recognition using opencv input arguments/csv file

I am trying to understand face recognition code using local binary histograms in opencv. i need to execute code for comparing output can any one tell me what arguments should i need to pass.Code is given at http://docs.opencv.org/modules/contrib/doc/facerec/facerec_tutorial.html#eigenfaces-in-opencv please tell me which data set i need to give as input and from where i can get it and please tell me the exact format of giving input at command line.

2013-11-29 10:05:15 -0600 commented answer Error in optical flow opencv function

I just want to know what could be the reason. please help

2013-11-29 10:04:15 -0600 commented answer Error in optical flow opencv function

It got crashed at goodFeaturesToTrack( imgB,cornersB,maxCorners,qualityLevel,minDistance,cv::Mat()); This statement is used twice in code it works perfectly for first i.e for imgA but got crashed at second

2013-11-29 09:18:36 -0600 asked a question Error in optical flow opencv function

I am trying to find the optical flow in 2 images . My code got crashed after taking many seconds for executions.code is shown below . please help me resolving this error . I am unable to find the reason. it gives this msg Windows has triggered a breakpoint in newproject.exe.

This may be due to a corruption of the heap, which indicates a bug in newproject.exe or any of the DLLs it has loaded.

This may also be due to the user pressing F12 while newproject.exe has focus.

The output window may have more diagnostic information.

 void optical()
{   
// Load two images and allocate other structures

    Mat imgA = imread("a.jpg", CV_LOAD_IMAGE_GRAYSCALE);
    Mat imgB = imread("c.jpg", CV_LOAD_IMAGE_GRAYSCALE);
    Size img_sz = imgA.size();
    Mat imgC(img_sz,1);
    int win_size = 15;

    int maxCorners = 20;
    double qualityLevel = 0.05;
    double minDistance = 5.0;
    int blockSize = 3;

    double k = 0.04;
    std::vector<cv::Point2f> cornersA;
    cornersA.reserve(maxCorners);
    std::vector<cv::Point2f> cornersB;
    cornersB.reserve(maxCorners);

    goodFeaturesToTrack( imgA,cornersA,maxCorners,qualityLevel,minDistance,cv::Mat());

    goodFeaturesToTrack( imgB,cornersB,maxCorners,qualityLevel,minDistance,cv::Mat());
    cout<<"Runniung"<<endl;
    cornerSubPix( imgA, cornersA, Size( win_size, win_size ), Size( -1, -1 ),

    TermCriteria( CV_TERMCRIT_ITER | CV_TERMCRIT_EPS, 20, 0.03 ) );
    cornerSubPix( imgB, cornersB, Size( win_size, win_size ), Size( -1, -1 ),

    TermCriteria( CV_TERMCRIT_ITER | CV_TERMCRIT_EPS, 20, 0.03 ) );

    // Call Lucas Kanade algorithm
    CvSize pyr_sz = Size( img_sz.width+8, img_sz.height/3 );
    std::vector<uchar> features_found;
    features_found.reserve(maxCorners);

    std::vector<float> feature_errors;
    feature_errors.reserve(maxCorners);

    calcOpticalFlowPyrLK( imgA, imgB, cornersA, cornersB, features_found, feature_errors ,Size( win_size, win_size ), 5,cvTermCriteria( CV_TERMCRIT_ITER | CV_TERMCRIT_EPS, 20, 0.3 ), 0 );

    // Make an image of the results


    for( int i=0; i < features_found.size(); i++ ){

     cout<<"Error is "<<feature_errors[i]<<endl;

     //continue;
     cout<<"Got it"<<endl;

     Point p0( ceil( cornersA[i].x ), ceil( cornersA[i].y ) );

     Point p1( ceil( cornersB[i].x ), ceil( cornersB[i].y ) );

     line( imgC, p0, p1, CV_RGB(255,255,255), 2 );

     }



     namedWindow( "ImageA", 0 );

     namedWindow( "ImageB", 0 );

     namedWindow( "LKpyr_OpticalFlow", 0 );



     imshow( "ImageA", imgA );

     imshow( "ImageB", imgB );

     imshow( "LKpyr_OpticalFlow", imgC );
     cvWaitKey(0);
    // return 0;

    //return 0;
}

int _tmain(int argc, _TCHAR* argv[])
{
 //  video obj("video.avi");
     optical_flow obj2;
   obj2.optical();
}
2013-11-24 08:46:08 -0600 commented answer After subraction of 4 neighbor pixels always give zero

Mat newimage= Mat(Frame.rows,Frame.cols,3); newimage.at<Vec3b>(j,i)=Frame.at<Vec3b>(j,i)-Frame.at<Vec3b>(j+1,i)- Frame.at<Vec3b>(j,i+1)- Frame.at<Vec3b>(j-1,i)- Frame.at<Vec3b>(j,i-1);

2013-11-24 08:33:07 -0600 commented answer After subraction of 4 neighbor pixels always give zero

now what i have to change in my code ? when i use vec3d instead of vec3b my code get crashed

2013-11-24 06:21:35 -0600 asked a question After subraction of 4 neighbor pixels always give zero

I am trying to take difference of center pixel with 4 neighbor and add them and then replace the original with that difference value. but it always replace pixel with zero. I don't what i am doing wrong. thanks for any help

// newproject.cpp : Defines the entry point for the console application.

#include "stdafx.h"
#include "highgui.h"
#include <stdio.h>
#include <cv.h>
#include <highgui.h>
#include <stdio.h>
#include <conio.h>
#include <opencv2/imgproc/imgproc.hpp>  // Gaussian Blur
#include <opencv2/core/core.hpp>        // Basic OpenCV structures (cv::Mat, Scalar)
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <conio.h>     using namespace cv;
 using namespace std;

  class frameprocessing{

  Mat hsv_base;
  MatND hist_base;

  public:
  void whatever(Mat Frame)
  {
    for(int i=0;i<Frame.cols;i++)
        for(int j=0;j<Frame.rows;j++)
        {
            if(i==0&&j==0)
            {

            //  cout<<"Check 1"<<endl;
                Frame.at<Vec3b>(j,i)=(Frame.at<Vec3b>(j,i)-(Frame.at<Vec3b>(j+1,i))+(Frame.at<Vec3b>(j,i)-Frame.at<Vec3b>(j,i+1))+(Frame.at<Vec3b>(j,i)-Frame.at<Vec3b>(j+1,i))+(Frame.at<Vec3b>(j,i)-Frame.at<Vec3b>(j,i+1)));

                Frame.at<Vec3b>(j,i)=(Frame.at<Vec3b>(j,i))[0]/4;
                Frame.at<Vec3b>(j,i)=(Frame.at<Vec3b>(j,i))[1]/4;
                Frame.at<Vec3b>(j,i)=(Frame.at<Vec3b>(j,i))[2]/4;

            }
            else if(i==Frame.cols-1&&j==Frame.rows-1)
            {
            //  cout<<"Check 2"<<endl;
                Frame.at<Vec3b>(j,i)=((Frame.at<Vec3b>(j-1,i)-Frame.at<Vec3b>(j,i))+(Frame.at<Vec3b>(j,i-1)+Frame.at<Vec3b>(j,i))+(Frame.at<Vec3b>(j-1,i)-Frame.at<Vec3b>(j,i))+(Frame.at<Vec3b>(j,i-1)+Frame.at<Vec3b>(j,i)));
                Frame.at<Vec3b>(j,i)=(Frame.at<Vec3b>(j,i))[0]/4;
                Frame.at<Vec3b>(j,i)=(Frame.at<Vec3b>(j,i))[1]/4;
                Frame.at<Vec3b>(j,i)=(Frame.at<Vec3b>(j,i))[2]/4;
            }
            else if(i==Frame.cols-1&&j==0)
            {
                                      //cout<<"Check 3"<<endl;
                Frame.at<Vec3b>(j,i)=((Frame.at<Vec3b>(j+1,i)-Frame.at<Vec3b>(j,i))+(Frame.at<Vec3b>(j,i-1)+Frame.at<Vec3b>(j,i))+(Frame.at<Vec3b>(j+1,i)-Frame.at<Vec3b>(j,i))+(Frame.at<Vec3b>(j,i-1)+Frame.at<Vec3b>(j,i)));
                Frame.at<Vec3b>(j,i)=(Frame.at<Vec3b>(j,i))[0]/4;
                Frame.at<Vec3b>(j,i)=(Frame.at<Vec3b>(j,i))[1]/4;
                Frame.at<Vec3b>(j,i)=(Frame.at<Vec3b>(j,i))[2]/4;
            }
            else if(i==0&&j==Frame.rows-1)
            {
            //  cout<<"Check 4"<<endl;
                Frame.at<Vec3b>(j,i)=((Frame.at<Vec3b>(j-1,i)-Frame.at<Vec3b>(j,i))+(Frame.at<Vec3b>(j,i+1)+Frame.at<Vec3b>(j,i))+(Frame.at<Vec3b>(j-1,i)-Frame.at<Vec3b>(j,i))+(Frame.at<Vec3b>(j,i+1)+Frame.at<Vec3b>(j,i)));
                Frame.at<Vec3b>(j,i)=(Frame.at<Vec3b>(j,i))[0]/4;
                Frame.at<Vec3b>(j,i)=(Frame.at<Vec3b>(j,i))[1]/4;
                Frame.at ...
(more)