Assertion failed (scn==3 || scn==4) cvtcolor line 3737. [2 Attachments]

classic Classic list List threaded Threaded
16 messages Options
Reply | Threaded
Open this post in threaded view
|

Assertion failed (scn==3 || scn==4) cvtcolor line 3737. [2 Attachments]

muhammadjahanzaibkhan89
Hi, i converting webcam video to grayscale .But i found error Assertion failed (scn==3 || scn==4) cvtcolor line 3737. code work well for images .But not working for ny type video.And i cant open avi files and found error  Assertion failed (size.width>0 && size.height>0) in imshow line 261.Using opencv 2.4.9.

 

 Kindly solve my problems.I am new in c++ and opencv and also in programing.
 

 

Reply | Threaded
Open this post in threaded view
|

Re: Assertion failed (scn==3 || scn==4) cvtcolor line 3737.

Fábián Kristóf - Szabolcs
Hi,


I think you are trying to process an empty frame. You should add this check before converting your image:


//image is a cv::Mat here

if (!image.empty()) {

    //convert

}


Bests,


Fabian


________________________________
Feladó: [hidden email] <[hidden email]>, meghatalmazó: [hidden email] [OpenCV] <[hidden email]>
Elküldve: 2017. november 28. 13:36
Címzett: [hidden email]
Tárgy: [OpenCV] Assertion failed (scn==3 || scn==4) cvtcolor line 3737. [2 Attachments]


[Attachment(s) from [hidden email] [OpenCV] included below]

Hi, i converting webcam video to grayscale .But i found error Assertion failed (scn==3 || scn==4) cvtcolor line 3737. code work well for images .But not working for ny type video.And i cant open avi files and found error

Assertion failed (size.width>0 && size.height>0) in imshow line 261.Using opencv 2.4.9.

Kindly solve my problems.I am new in c++ and opencv and also in programing.




Reply | Threaded
Open this post in threaded view
|

Re: Assertion failed (scn==3 || scn==4) cvtcolor line 3737.

muhammadjahanzaibkhan89
Fabian kristof thanku for response.i use this check . this is code.#include <opencv\cv.h>#include <opencv\highgui.h>
using namespace std;using namespace cv;
//our sensitivity value to be used in the absdiff() functionconst static int SENSITIVITY_VALUE = 20;//size of blur used to smooth the intensity image output from absdiff() functionconst static int BLUR_SIZE = 10;//we'll have just one object to search for//and keep track of its position.int theObject[2] = {0,0};//bounding rectangle of the object, we will use the center of this as its position.Rect objectBoundingRectangle = Rect(0,0,0,0);

//int to string helper functionstring intToString(int number){
    //this function has a number input and string output    std::stringstream ss;    ss << number;    return ss.str();}
void searchForMovement(Mat thresholdImage, Mat &cameraFeed){    //notice how we use the '&' operator for objectDetected and cameraFeed. This is because we wish    //to take the values passed into the function and manipulate them, rather than just working with a copy.    //eg. we draw to the cameraFeed to be displayed in the main() function.    bool objectDetected = false;    Mat temp;    thresholdImage.copyTo(temp);    //these two vectors needed for output of findContours    vector< vector<Point> > contours;    vector<Vec4i> hierarchy;    //find contours of filtered image using openCV findContours function    //findContours(temp,contours,hierarchy,CV_RETR_CCOMP,CV_CHAIN_APPROX_SIMPLE );// retrieves all contours    findContours(temp,contours,hierarchy,CV_RETR_EXTERNAL,CV_CHAIN_APPROX_SIMPLE );// retrieves external contours
    //if contours vector is not empty, we have found some objects    if(contours.size()>0)objectDetected=true;    else objectDetected = false;
    if(objectDetected){        //the largest contour is found at the end of the contours vector        //we will simply assume that the biggest contour is the object we are looking for.        vector< vector<Point> > largestContourVec;        largestContourVec.push_back(contours.at(contours.size()-1));        //make a bounding rectangle around the largest contour then find its centroid        //this will be the object's final estimated position.        objectBoundingRectangle = boundingRect(largestContourVec.at(0));        int xpos = objectBoundingRectangle.x+objectBoundingRectangle.width/2;        int ypos = objectBoundingRectangle.y+objectBoundingRectangle.height/2;
        //update the objects positions by changing the 'theObject' array values        theObject[0] = xpos , theObject[1] = ypos;    }    //make some temp x and y variables so we dont have to type out so much    int x = theObject[0];    int y = theObject[1];
    //draw some crosshairs around the object    circle(cameraFeed,Point(x,y),20,Scalar(0,255,0),2);    line(cameraFeed,Point(x,y),Point(x,y-25),Scalar(0,255,0),2);    line(cameraFeed,Point(x,y),Point(x,y+25),Scalar(0,255,0),2);    line(cameraFeed,Point(x,y),Point(x-25,y),Scalar(0,255,0),2);    line(cameraFeed,Point(x,y),Point(x+25,y),Scalar(0,255,0),2);
    //write the position of the object to the screen    putText(cameraFeed,"Tracking object at (" + intToString(x)+","+intToString(y)+")",Point(x,y),1,1,Scalar(255,0,0),2);


}int main(){
    VideoCapture cap(0);
while (true){    Mat frame;
    Mat grayscale;    if (!frame.empty())    cvtColor(frame, grayscale, CV_RGB2GRAY);    imshow("Debug Window",frame);    if (waitKey(30) >=0)    {        cout << "End of Stream";        break;    }}

    On Tuesday, November 28, 2017 3:51 AM, "Fábián Kristóf - Szabolcs [hidden email] [OpenCV]" <[hidden email]> wrote:
 

     Hi,
I think you are trying to process an empty frame. You should add this check before converting your image:
//image is a cv::Mat hereif (!image.empty()) {    //convert}
Bests,
Fabian

Feladó: [hidden email] <[hidden email]>, meghatalmazó: [hidden email] [OpenCV] <[hidden email]>
Elküldve: 2017. november 28. 13:36
Címzett: [hidden email]
Tárgy: [OpenCV] Assertion failed (scn==3 || scn==4) cvtcolor line 3737. [2 Attachments]  [Attachment(s) from [hidden email] [OpenCV] included below]Hi, i converting webcam video to grayscale .But i found error Assertion failed (scn==3 || scn==4) cvtcolor line 3737. code work well for images .But not working for ny type video.And i cant open avi files and found error Assertion failed (size.width>0 && size.height>0) in imshow line 261.Using opencv 2.4.9.

Kindly solve my problems.I am new in c++ and opencv and also in programing.

  #yiv5987278765 #yiv5987278765 -- #yiv5987278765ygrp-mkp {border:1px solid #d8d8d8;font-family:Arial;margin:10px 0;padding:0 10px;}#yiv5987278765 #yiv5987278765ygrp-mkp hr {border:1px solid #d8d8d8;}#yiv5987278765 #yiv5987278765ygrp-mkp #yiv5987278765hd {color:#628c2a;font-size:85%;font-weight:700;line-height:122%;margin:10px 0;}#yiv5987278765 #yiv5987278765ygrp-mkp #yiv5987278765ads {margin-bottom:10px;}#yiv5987278765 #yiv5987278765ygrp-mkp .yiv5987278765ad {padding:0 0;}#yiv5987278765 #yiv5987278765ygrp-mkp .yiv5987278765ad p {margin:0;}#yiv5987278765 #yiv5987278765ygrp-mkp .yiv5987278765ad a {color:#0000ff;text-decoration:none;}#yiv5987278765 #yiv5987278765ygrp-sponsor #yiv5987278765ygrp-lc {font-family:Arial;}#yiv5987278765 #yiv5987278765ygrp-sponsor #yiv5987278765ygrp-lc #yiv5987278765hd {margin:10px 0px;font-weight:700;font-size:78%;line-height:122%;}#yiv5987278765 #yiv5987278765ygrp-sponsor #yiv5987278765ygrp-lc .yiv5987278765ad {margin-bottom:10px;padding:0 0;}#yiv5987278765 #yiv5987278765actions {font-family:Verdana;font-size:11px;padding:10px 0;}#yiv5987278765 #yiv5987278765activity {background-color:#e0ecee;float:left;font-family:Verdana;font-size:10px;padding:10px;}#yiv5987278765 #yiv5987278765activity span {font-weight:700;}#yiv5987278765 #yiv5987278765activity span:first-child {text-transform:uppercase;}#yiv5987278765 #yiv5987278765activity span a {color:#5085b6;text-decoration:none;}#yiv5987278765 #yiv5987278765activity span span {color:#ff7900;}#yiv5987278765 #yiv5987278765activity span .yiv5987278765underline {text-decoration:underline;}#yiv5987278765 .yiv5987278765attach {clear:both;display:table;font-family:Arial;font-size:12px;padding:10px 0;width:400px;}#yiv5987278765 .yiv5987278765attach div a {text-decoration:none;}#yiv5987278765 .yiv5987278765attach img {border:none;padding-right:5px;}#yiv5987278765 .yiv5987278765attach label {display:block;margin-bottom:5px;}#yiv5987278765 .yiv5987278765attach label a {text-decoration:none;}#yiv5987278765 blockquote {margin:0 0 0 4px;}#yiv5987278765 .yiv5987278765bold {font-family:Arial;font-size:13px;font-weight:700;}#yiv5987278765 .yiv5987278765bold a {text-decoration:none;}#yiv5987278765 dd.yiv5987278765last p a {font-family:Verdana;font-weight:700;}#yiv5987278765 dd.yiv5987278765last p span {margin-right:10px;font-family:Verdana;font-weight:700;}#yiv5987278765 dd.yiv5987278765last p span.yiv5987278765yshortcuts {margin-right:0;}#yiv5987278765 div.yiv5987278765attach-table div div a {text-decoration:none;}#yiv5987278765 div.yiv5987278765attach-table {width:400px;}#yiv5987278765 div.yiv5987278765file-title a, #yiv5987278765 div.yiv5987278765file-title a:active, #yiv5987278765 div.yiv5987278765file-title a:hover, #yiv5987278765 div.yiv5987278765file-title a:visited {text-decoration:none;}#yiv5987278765 div.yiv5987278765photo-title a, #yiv5987278765 div.yiv5987278765photo-title a:active, #yiv5987278765 div.yiv5987278765photo-title a:hover, #yiv5987278765 div.yiv5987278765photo-title a:visited {text-decoration:none;}#yiv5987278765 div#yiv5987278765ygrp-mlmsg #yiv5987278765ygrp-msg p a span.yiv5987278765yshortcuts {font-family:Verdana;font-size:10px;font-weight:normal;}#yiv5987278765 .yiv5987278765green {color:#628c2a;}#yiv5987278765 .yiv5987278765MsoNormal {margin:0 0 0 0;}#yiv5987278765 o {font-size:0;}#yiv5987278765 #yiv5987278765photos div {float:left;width:72px;}#yiv5987278765 #yiv5987278765photos div div {border:1px solid #666666;min-height:62px;overflow:hidden;width:62px;}#yiv5987278765 #yiv5987278765photos div label {color:#666666;font-size:10px;overflow:hidden;text-align:center;white-space:nowrap;width:64px;}#yiv5987278765 #yiv5987278765reco-category {font-size:77%;}#yiv5987278765 #yiv5987278765reco-desc {font-size:77%;}#yiv5987278765 .yiv5987278765replbq {margin:4px;}#yiv5987278765 #yiv5987278765ygrp-actbar div a:first-child {margin-right:2px;padding-right:5px;}#yiv5987278765 #yiv5987278765ygrp-mlmsg {font-size:13px;font-family:Arial, helvetica, clean, sans-serif;}#yiv5987278765 #yiv5987278765ygrp-mlmsg table {font-size:inherit;font:100%;}#yiv5987278765 #yiv5987278765ygrp-mlmsg select, #yiv5987278765 input, #yiv5987278765 textarea {font:99% Arial, Helvetica, clean, sans-serif;}#yiv5987278765 #yiv5987278765ygrp-mlmsg pre, #yiv5987278765 code {font:115% monospace;}#yiv5987278765 #yiv5987278765ygrp-mlmsg * {line-height:1.22em;}#yiv5987278765 #yiv5987278765ygrp-mlmsg #yiv5987278765logo {padding-bottom:10px;}#yiv5987278765 #yiv5987278765ygrp-msg p a {font-family:Verdana;}#yiv5987278765 #yiv5987278765ygrp-msg p#yiv5987278765attach-count span {color:#1E66AE;font-weight:700;}#yiv5987278765 #yiv5987278765ygrp-reco #yiv5987278765reco-head {color:#ff7900;font-weight:700;}#yiv5987278765 #yiv5987278765ygrp-reco {margin-bottom:20px;padding:0px;}#yiv5987278765 #yiv5987278765ygrp-sponsor #yiv5987278765ov li a {font-size:130%;text-decoration:none;}#yiv5987278765 #yiv5987278765ygrp-sponsor #yiv5987278765ov li {font-size:77%;list-style-type:square;padding:6px 0;}#yiv5987278765 #yiv5987278765ygrp-sponsor #yiv5987278765ov ul {margin:0;padding:0 0 0 8px;}#yiv5987278765 #yiv5987278765ygrp-text {font-family:Georgia;}#yiv5987278765 #yiv5987278765ygrp-text p {margin:0 0 1em 0;}#yiv5987278765 #yiv5987278765ygrp-text tt {font-size:120%;}#yiv5987278765 #yiv5987278765ygrp-vital ul li:last-child {border-right:none !important;}#yiv5987278765

   
Reply | Threaded
Open this post in threaded view
|

Re: Assertion failed (scn==3 || scn==4) cvtcolor line 3737.

Fábián Kristóf - Szabolcs
You are not reading the video stream. I'd modify your main like this:


int main(){

    VideoCapture cap(0);
    if (cap.isOpened())
    {
         Mat grayscale;
         Mat frame;
         while (true)
         {
             cap.read(frame);

             if (frame.empty())
                  continue;

            cvtColor(frame, grayscale, CV_RGB2GRAY);
            imshow("Debug Window",frame);
            if (waitKey(30) >=0)
           {
               cout << "End of Stream";
               break;
           }
        }
    }
}



________________________________
Feladó: [hidden email] <[hidden email]>, meghatalmazó: muhammad jahanzaib khan [hidden email] [OpenCV] <[hidden email]>
Elküldve: 2017. november 28. 13:59
Címzett: [hidden email]
Tárgy: Re: [OpenCV] Assertion failed (scn==3 || scn==4) cvtcolor line 3737.



Fabian kristof thanku for response.
i use this check .
 this is code.
#include <opencv\cv.h>
#include <opencv\highgui.h>

using namespace std;
using namespace cv;

//our sensitivity value to be used in the absdiff() function
const static int SENSITIVITY_VALUE = 20;
//size of blur used to smooth the intensity image output from absdiff() function
const static int BLUR_SIZE = 10;
//we'll have just one object to search for
//and keep track of its position.
int theObject[2] = {0,0};
//bounding rectangle of the object, we will use the center of this as its position.
Rect objectBoundingRectangle = Rect(0,0,0,0);


//int to string helper function
string intToString(int number){

    //this function has a number input and string output
    std::stringstream ss;
    ss << number;
    return ss.str();
}

void searchForMovement(Mat thresholdImage, Mat &cameraFeed){
    //notice how we use the '&' operator for objectDetected and cameraFeed. This is because we wish
    //to take the values passed into the function and manipulate them, rather than just working with a copy.
    //eg. we draw to the cameraFeed to be displayed in the main() function.
    bool objectDetected = false;
    Mat temp;
    thresholdImage.copyTo(temp);
    //these two vectors needed for output of findContours
    vector< vector<Point> > contours;
    vector<Vec4i> hierarchy;
    //find contours of filtered image using openCV findContours function
    //findContours(temp,contours,hierarchy,CV_RETR_CCOMP,CV_CHAIN_APPROX_SIMPLE );// retrieves all contours
    findContours(temp,contours,hierarchy,CV_RETR_EXTERNAL,CV_CHAIN_APPROX_SIMPLE );// retrieves external contours

    //if contours vector is not empty, we have found some objects
    if(contours.size()>0)objectDetected=true;
    else objectDetected = false;

    if(objectDetected){
        //the largest contour is found at the end of the contours vector
        //we will simply assume that the biggest contour is the object we are looking for.
        vector< vector<Point> > largestContourVec;
        largestContourVec.push_back(contours.at(contours.size()-1));
        //make a bounding rectangle around the largest contour then find its centroid
        //this will be the object's final estimated position.
        objectBoundingRectangle = boundingRect(largestContourVec.at(0));
        int xpos = objectBoundingRectangle.x+objectBoundingRectangle.width/2;
        int ypos = objectBoundingRectangle.y+objectBoundingRectangle.height/2;

        //update the objects positions by changing the 'theObject' array values
        theObject[0] = xpos , theObject[1] = ypos;
    }
    //make some temp x and y variables so we dont have to type out so much
    int x = theObject[0];
    int y = theObject[1];

    //draw some crosshairs around the object
    circle(cameraFeed,Point(x,y),20,Scalar(0,255,0),2);
    line(cameraFeed,Point(x,y),Point(x,y-25),Scalar(0,255,0),2);
    line(cameraFeed,Point(x,y),Point(x,y+25),Scalar(0,255,0),2);
    line(cameraFeed,Point(x,y),Point(x-25,y),Scalar(0,255,0),2);
    line(cameraFeed,Point(x,y),Point(x+25,y),Scalar(0,255,0),2);

    //write the position of the object to the screen
    putText(cameraFeed,"Tracking object at (" + intToString(x)+","+intToString(y)+")",Point(x,y),1,1,Scalar(255,0,0),2);



}
int main(){

    VideoCapture cap(0);

while (true)
{
    Mat frame;

    Mat grayscale;
    if (!frame.empty())
    cvtColor(frame, grayscale, CV_RGB2GRAY);
    imshow("Debug Window",frame);
    if (waitKey(30) >=0)
    {
        cout << "End of Stream";
        break;
    }
}


On Tuesday, November 28, 2017 3:51 AM, "Fábián Kristóf - Szabolcs [hidden email] [OpenCV]" <[hidden email]> wrote:



Hi,

I think you are trying to process an empty frame. You should add this check before converting your image:

//image is a cv::Mat here
if (!image.empty()) {
    //convert
}

Bests,

Fabian


________________________________
Feladó: [hidden email] <[hidden email]>, meghatalmazó: [hidden email] [OpenCV] <[hidden email]>
Elküldve: 2017. november 28. 13:36
Címzett: [hidden email]
Tárgy: [OpenCV] Assertion failed (scn==3 || scn==4) cvtcolor line 3737. [2 Attachments]


[Attachment(s)<https://mail.yahoo.com/?.src=ym&soc_src=mail&soc_trk=ma#x_TopText> from [hidden email] [OpenCV] included below]
Hi, i converting webcam video to grayscale .But i found error Assertion failed (scn==3 || scn==4) cvtcolor line 3737. code work well for images .But not working for ny type video.And i cant open avi files and found error
Assertion failed (size.width>0 && size.height>0) in imshow line 261.Using opencv 2.4.9.

Kindly solve my problems.I am new in c++ and opencv and also in programing.






Reply | Threaded
Open this post in threaded view
|

Re: Assertion failed (scn==3 || scn==4) cvtcolor line 3737.

muhammadjahanzaibkhan89
its not work for saved avi flies. how it work for saved files?
 

Reply | Threaded
Open this post in threaded view
|

Re: Assertion failed (scn==3 || scn==4) cvtcolor line 3737.

Fábián Kristóf - Szabolcs
You write:


VideoCapture cap("C:/PathToYourVideo.mp4"); //for example


or


VideoCapture cap;

cap.open("C:/PathToYourVideo.mp4");


________________________________
Feladó: [hidden email] <[hidden email]>, meghatalmazó: [hidden email] [OpenCV] <[hidden email]>
Elküldve: 2017. november 28. 14:50
Címzett: [hidden email]
Tárgy: Re: [OpenCV] Assertion failed (scn==3 || scn==4) cvtcolor line 3737.



its not work for saved avi flies.

how it work for saved files?



Reply | Threaded
Open this post in threaded view
|

Re: Assertion failed (scn==3 || scn==4) cvtcolor line 3737.

muhammadjahanzaibkhan89
i write this but some files  not open.like 768x576.avi file is not open but tree.avi file open.thes files are in the opencv example folder.

    On Tuesday, November 28, 2017 5:13 AM, "Fábián Kristóf - Szabolcs [hidden email] [OpenCV]" <[hidden email]> wrote:
 

     You write:
VideoCapture cap("C:/PathToYourVideo.mp4"); //for example
or 
VideoCapture cap;cap.open("C:/PathToYourVideo.mp4");

Feladó: [hidden email] <[hidden email]>, meghatalmazó: [hidden email] [OpenCV] <[hidden email]>
Elküldve: 2017. november 28. 14:50
Címzett: [hidden email]
Tárgy: Re: [OpenCV] Assertion failed (scn==3 || scn==4) cvtcolor line 3737.  its not work for saved avi flies.how it work for saved files?
  #yiv2904444385 #yiv2904444385 -- #yiv2904444385ygrp-mkp {border:1px solid #d8d8d8;font-family:Arial;margin:10px 0;padding:0 10px;}#yiv2904444385 #yiv2904444385ygrp-mkp hr {border:1px solid #d8d8d8;}#yiv2904444385 #yiv2904444385ygrp-mkp #yiv2904444385hd {color:#628c2a;font-size:85%;font-weight:700;line-height:122%;margin:10px 0;}#yiv2904444385 #yiv2904444385ygrp-mkp #yiv2904444385ads {margin-bottom:10px;}#yiv2904444385 #yiv2904444385ygrp-mkp .yiv2904444385ad {padding:0 0;}#yiv2904444385 #yiv2904444385ygrp-mkp .yiv2904444385ad p {margin:0;}#yiv2904444385 #yiv2904444385ygrp-mkp .yiv2904444385ad a {color:#0000ff;text-decoration:none;}#yiv2904444385 #yiv2904444385ygrp-sponsor #yiv2904444385ygrp-lc {font-family:Arial;}#yiv2904444385 #yiv2904444385ygrp-sponsor #yiv2904444385ygrp-lc #yiv2904444385hd {margin:10px 0px;font-weight:700;font-size:78%;line-height:122%;}#yiv2904444385 #yiv2904444385ygrp-sponsor #yiv2904444385ygrp-lc .yiv2904444385ad {margin-bottom:10px;padding:0 0;}#yiv2904444385 #yiv2904444385actions {font-family:Verdana;font-size:11px;padding:10px 0;}#yiv2904444385 #yiv2904444385activity {background-color:#e0ecee;float:left;font-family:Verdana;font-size:10px;padding:10px;}#yiv2904444385 #yiv2904444385activity span {font-weight:700;}#yiv2904444385 #yiv2904444385activity span:first-child {text-transform:uppercase;}#yiv2904444385 #yiv2904444385activity span a {color:#5085b6;text-decoration:none;}#yiv2904444385 #yiv2904444385activity span span {color:#ff7900;}#yiv2904444385 #yiv2904444385activity span .yiv2904444385underline {text-decoration:underline;}#yiv2904444385 .yiv2904444385attach {clear:both;display:table;font-family:Arial;font-size:12px;padding:10px 0;width:400px;}#yiv2904444385 .yiv2904444385attach div a {text-decoration:none;}#yiv2904444385 .yiv2904444385attach img {border:none;padding-right:5px;}#yiv2904444385 .yiv2904444385attach label {display:block;margin-bottom:5px;}#yiv2904444385 .yiv2904444385attach label a {text-decoration:none;}#yiv2904444385 blockquote {margin:0 0 0 4px;}#yiv2904444385 .yiv2904444385bold {font-family:Arial;font-size:13px;font-weight:700;}#yiv2904444385 .yiv2904444385bold a {text-decoration:none;}#yiv2904444385 dd.yiv2904444385last p a {font-family:Verdana;font-weight:700;}#yiv2904444385 dd.yiv2904444385last p span {margin-right:10px;font-family:Verdana;font-weight:700;}#yiv2904444385 dd.yiv2904444385last p span.yiv2904444385yshortcuts {margin-right:0;}#yiv2904444385 div.yiv2904444385attach-table div div a {text-decoration:none;}#yiv2904444385 div.yiv2904444385attach-table {width:400px;}#yiv2904444385 div.yiv2904444385file-title a, #yiv2904444385 div.yiv2904444385file-title a:active, #yiv2904444385 div.yiv2904444385file-title a:hover, #yiv2904444385 div.yiv2904444385file-title a:visited {text-decoration:none;}#yiv2904444385 div.yiv2904444385photo-title a, #yiv2904444385 div.yiv2904444385photo-title a:active, #yiv2904444385 div.yiv2904444385photo-title a:hover, #yiv2904444385 div.yiv2904444385photo-title a:visited {text-decoration:none;}#yiv2904444385 div#yiv2904444385ygrp-mlmsg #yiv2904444385ygrp-msg p a span.yiv2904444385yshortcuts {font-family:Verdana;font-size:10px;font-weight:normal;}#yiv2904444385 .yiv2904444385green {color:#628c2a;}#yiv2904444385 .yiv2904444385MsoNormal {margin:0 0 0 0;}#yiv2904444385 o {font-size:0;}#yiv2904444385 #yiv2904444385photos div {float:left;width:72px;}#yiv2904444385 #yiv2904444385photos div div {border:1px solid #666666;min-height:62px;overflow:hidden;width:62px;}#yiv2904444385 #yiv2904444385photos div label {color:#666666;font-size:10px;overflow:hidden;text-align:center;white-space:nowrap;width:64px;}#yiv2904444385 #yiv2904444385reco-category {font-size:77%;}#yiv2904444385 #yiv2904444385reco-desc {font-size:77%;}#yiv2904444385 .yiv2904444385replbq {margin:4px;}#yiv2904444385 #yiv2904444385ygrp-actbar div a:first-child {margin-right:2px;padding-right:5px;}#yiv2904444385 #yiv2904444385ygrp-mlmsg {font-size:13px;font-family:Arial, helvetica, clean, sans-serif;}#yiv2904444385 #yiv2904444385ygrp-mlmsg table {font-size:inherit;font:100%;}#yiv2904444385 #yiv2904444385ygrp-mlmsg select, #yiv2904444385 input, #yiv2904444385 textarea {font:99% Arial, Helvetica, clean, sans-serif;}#yiv2904444385 #yiv2904444385ygrp-mlmsg pre, #yiv2904444385 code {font:115% monospace;}#yiv2904444385 #yiv2904444385ygrp-mlmsg * {line-height:1.22em;}#yiv2904444385 #yiv2904444385ygrp-mlmsg #yiv2904444385logo {padding-bottom:10px;}#yiv2904444385 #yiv2904444385ygrp-msg p a {font-family:Verdana;}#yiv2904444385 #yiv2904444385ygrp-msg p#yiv2904444385attach-count span {color:#1E66AE;font-weight:700;}#yiv2904444385 #yiv2904444385ygrp-reco #yiv2904444385reco-head {color:#ff7900;font-weight:700;}#yiv2904444385 #yiv2904444385ygrp-reco {margin-bottom:20px;padding:0px;}#yiv2904444385 #yiv2904444385ygrp-sponsor #yiv2904444385ov li a {font-size:130%;text-decoration:none;}#yiv2904444385 #yiv2904444385ygrp-sponsor #yiv2904444385ov li {font-size:77%;list-style-type:square;padding:6px 0;}#yiv2904444385 #yiv2904444385ygrp-sponsor #yiv2904444385ov ul {margin:0;padding:0 0 0 8px;}#yiv2904444385 #yiv2904444385ygrp-text {font-family:Georgia;}#yiv2904444385 #yiv2904444385ygrp-text p {margin:0 0 1em 0;}#yiv2904444385 #yiv2904444385ygrp-text tt {font-size:120%;}#yiv2904444385 #yiv2904444385ygrp-vital ul li:last-child {border-right:none !important;}#yiv2904444385

   
Reply | Threaded
Open this post in threaded view
|

Re: Assertion failed (scn==3 || scn==4) cvtcolor line 3737.

Fábián Kristóf - Szabolcs
Well then maybe add some prefix or postfix to your videos..like 768x576vid.avi..


________________________________
Feladó: [hidden email] <[hidden email]>, meghatalmazó: muhammad jahanzaib khan [hidden email] [OpenCV] <[hidden email]>
Elküldve: 2017. november 28. 15:24
Címzett: [hidden email]
Tárgy: Re: [OpenCV] Assertion failed (scn==3 || scn==4) cvtcolor line 3737.



i write this but some files  not open.like 768x576.avi file is not open but tree.avi file open.thes files are in the opencv example folder.


On Tuesday, November 28, 2017 5:13 AM, "Fábián Kristóf - Szabolcs [hidden email] [OpenCV]" <[hidden email]> wrote:



You write:

VideoCapture cap("C:/PathToYourVideo.mp4"); //for example

or

VideoCapture cap;
cap.open("C:/PathToYourVideo.mp4");


________________________________
Feladó: [hidden email] <[hidden email]>, meghatalmazó: [hidden email] [OpenCV] <[hidden email]>
Elküldve: 2017. november 28. 14:50
Címzett: [hidden email]
Tárgy: Re: [OpenCV] Assertion failed (scn==3 || scn==4) cvtcolor line 3737.


its not work for saved avi flies.
how it work for saved files?





Reply | Threaded
Open this post in threaded view
|

Re: Assertion failed (scn==3 || scn==4) cvtcolor line 3737.

muhammadjahanzaibkhan89
sorry sir i have no idea about prefix and postfix.how add thes kindly give me an example.


    On Tuesday, November 28, 2017 5:34 AM, "Fábián Kristóf - Szabolcs [hidden email] [OpenCV]" <[hidden email]> wrote:
 

     Well then maybe add some prefix or postfix to your videos..like 768x576vid.avi..

Feladó: [hidden email] <[hidden email]>, meghatalmazó: muhammad jahanzaib khan [hidden email] [OpenCV] <[hidden email]>
Elküldve: 2017. november 28. 15:24
Címzett: [hidden email]
Tárgy: Re: [OpenCV] Assertion failed (scn==3 || scn==4) cvtcolor line 3737.  i write this but some files  not open.like 768x576.avi file is not open but tree.avi file open.thes files are in the opencv example folder.

On Tuesday, November 28, 2017 5:13 AM, "Fábián Kristóf - Szabolcs [hidden email] [OpenCV]" <[hidden email]> wrote:


 You write:
VideoCapture cap("C:/PathToYourVideo.mp4"); //for example
or 
VideoCapture cap;cap.open("C:/PathToYourVideo.mp4");

Feladó: [hidden email] <[hidden email]>, meghatalmazó: [hidden email] [OpenCV] <[hidden email]>
Elküldve: 2017. november 28. 14:50
Címzett: [hidden email]
Tárgy: Re: [OpenCV] Assertion failed (scn==3 || scn==4) cvtcolor line 3737.  its not work for saved avi flies.how it work for saved files?


  #yiv1815355550 #yiv1815355550 -- #yiv1815355550ygrp-mkp {border:1px solid #d8d8d8;font-family:Arial;margin:10px 0;padding:0 10px;}#yiv1815355550 #yiv1815355550ygrp-mkp hr {border:1px solid #d8d8d8;}#yiv1815355550 #yiv1815355550ygrp-mkp #yiv1815355550hd {color:#628c2a;font-size:85%;font-weight:700;line-height:122%;margin:10px 0;}#yiv1815355550 #yiv1815355550ygrp-mkp #yiv1815355550ads {margin-bottom:10px;}#yiv1815355550 #yiv1815355550ygrp-mkp .yiv1815355550ad {padding:0 0;}#yiv1815355550 #yiv1815355550ygrp-mkp .yiv1815355550ad p {margin:0;}#yiv1815355550 #yiv1815355550ygrp-mkp .yiv1815355550ad a {color:#0000ff;text-decoration:none;}#yiv1815355550 #yiv1815355550ygrp-sponsor #yiv1815355550ygrp-lc {font-family:Arial;}#yiv1815355550 #yiv1815355550ygrp-sponsor #yiv1815355550ygrp-lc #yiv1815355550hd {margin:10px 0px;font-weight:700;font-size:78%;line-height:122%;}#yiv1815355550 #yiv1815355550ygrp-sponsor #yiv1815355550ygrp-lc .yiv1815355550ad {margin-bottom:10px;padding:0 0;}#yiv1815355550 #yiv1815355550actions {font-family:Verdana;font-size:11px;padding:10px 0;}#yiv1815355550 #yiv1815355550activity {background-color:#e0ecee;float:left;font-family:Verdana;font-size:10px;padding:10px;}#yiv1815355550 #yiv1815355550activity span {font-weight:700;}#yiv1815355550 #yiv1815355550activity span:first-child {text-transform:uppercase;}#yiv1815355550 #yiv1815355550activity span a {color:#5085b6;text-decoration:none;}#yiv1815355550 #yiv1815355550activity span span {color:#ff7900;}#yiv1815355550 #yiv1815355550activity span .yiv1815355550underline {text-decoration:underline;}#yiv1815355550 .yiv1815355550attach {clear:both;display:table;font-family:Arial;font-size:12px;padding:10px 0;width:400px;}#yiv1815355550 .yiv1815355550attach div a {text-decoration:none;}#yiv1815355550 .yiv1815355550attach img {border:none;padding-right:5px;}#yiv1815355550 .yiv1815355550attach label {display:block;margin-bottom:5px;}#yiv1815355550 .yiv1815355550attach label a {text-decoration:none;}#yiv1815355550 blockquote {margin:0 0 0 4px;}#yiv1815355550 .yiv1815355550bold {font-family:Arial;font-size:13px;font-weight:700;}#yiv1815355550 .yiv1815355550bold a {text-decoration:none;}#yiv1815355550 dd.yiv1815355550last p a {font-family:Verdana;font-weight:700;}#yiv1815355550 dd.yiv1815355550last p span {margin-right:10px;font-family:Verdana;font-weight:700;}#yiv1815355550 dd.yiv1815355550last p span.yiv1815355550yshortcuts {margin-right:0;}#yiv1815355550 div.yiv1815355550attach-table div div a {text-decoration:none;}#yiv1815355550 div.yiv1815355550attach-table {width:400px;}#yiv1815355550 div.yiv1815355550file-title a, #yiv1815355550 div.yiv1815355550file-title a:active, #yiv1815355550 div.yiv1815355550file-title a:hover, #yiv1815355550 div.yiv1815355550file-title a:visited {text-decoration:none;}#yiv1815355550 div.yiv1815355550photo-title a, #yiv1815355550 div.yiv1815355550photo-title a:active, #yiv1815355550 div.yiv1815355550photo-title a:hover, #yiv1815355550 div.yiv1815355550photo-title a:visited {text-decoration:none;}#yiv1815355550 div#yiv1815355550ygrp-mlmsg #yiv1815355550ygrp-msg p a span.yiv1815355550yshortcuts {font-family:Verdana;font-size:10px;font-weight:normal;}#yiv1815355550 .yiv1815355550green {color:#628c2a;}#yiv1815355550 .yiv1815355550MsoNormal {margin:0 0 0 0;}#yiv1815355550 o {font-size:0;}#yiv1815355550 #yiv1815355550photos div {float:left;width:72px;}#yiv1815355550 #yiv1815355550photos div div {border:1px solid #666666;min-height:62px;overflow:hidden;width:62px;}#yiv1815355550 #yiv1815355550photos div label {color:#666666;font-size:10px;overflow:hidden;text-align:center;white-space:nowrap;width:64px;}#yiv1815355550 #yiv1815355550reco-category {font-size:77%;}#yiv1815355550 #yiv1815355550reco-desc {font-size:77%;}#yiv1815355550 .yiv1815355550replbq {margin:4px;}#yiv1815355550 #yiv1815355550ygrp-actbar div a:first-child {margin-right:2px;padding-right:5px;}#yiv1815355550 #yiv1815355550ygrp-mlmsg {font-size:13px;font-family:Arial, helvetica, clean, sans-serif;}#yiv1815355550 #yiv1815355550ygrp-mlmsg table {font-size:inherit;font:100%;}#yiv1815355550 #yiv1815355550ygrp-mlmsg select, #yiv1815355550 input, #yiv1815355550 textarea {font:99% Arial, Helvetica, clean, sans-serif;}#yiv1815355550 #yiv1815355550ygrp-mlmsg pre, #yiv1815355550 code {font:115% monospace;}#yiv1815355550 #yiv1815355550ygrp-mlmsg * {line-height:1.22em;}#yiv1815355550 #yiv1815355550ygrp-mlmsg #yiv1815355550logo {padding-bottom:10px;}#yiv1815355550 #yiv1815355550ygrp-msg p a {font-family:Verdana;}#yiv1815355550 #yiv1815355550ygrp-msg p#yiv1815355550attach-count span {color:#1E66AE;font-weight:700;}#yiv1815355550 #yiv1815355550ygrp-reco #yiv1815355550reco-head {color:#ff7900;font-weight:700;}#yiv1815355550 #yiv1815355550ygrp-reco {margin-bottom:20px;padding:0px;}#yiv1815355550 #yiv1815355550ygrp-sponsor #yiv1815355550ov li a {font-size:130%;text-decoration:none;}#yiv1815355550 #yiv1815355550ygrp-sponsor #yiv1815355550ov li {font-size:77%;list-style-type:square;padding:6px 0;}#yiv1815355550 #yiv1815355550ygrp-sponsor #yiv1815355550ov ul {margin:0;padding:0 0 0 8px;}#yiv1815355550 #yiv1815355550ygrp-text {font-family:Georgia;}#yiv1815355550 #yiv1815355550ygrp-text p {margin:0 0 1em 0;}#yiv1815355550 #yiv1815355550ygrp-text tt {font-size:120%;}#yiv1815355550 #yiv1815355550ygrp-vital ul li:last-child {border-right:none !important;}#yiv1815355550

   
Reply | Threaded
Open this post in threaded view
|

Re: Assertion failed (scn==3 || scn==4) cvtcolor line 3737.

Leonardo Bocchi
In reply to this post by Fábián Kristóf - Szabolcs
Hi, it could be also that your video is not in colour.

scn == 3 or scn == 4 means an RGB (or RGBA) video. In case it is a
grayscale, you have scn = 1 and the assertion fails.

Leonardo



On 28/11/2017 12:51, Fábián Kristóf - Szabolcs [hidden email]
[OpenCV] wrote:

>
> Hi,
>
>
> I think you are trying to process an empty frame. You should add this
> check before converting your image:
>
>
> //image is a cv::Mat here
>
> if (!image.empty()) {
>
> //convert
>
> }
>
>
> Bests,
>
>
> Fabian
>
>
>
> ------------------------------------------------------------------------
> *Feladó:* [hidden email] <[hidden email]>,
> meghatalmazó: [hidden email] [OpenCV]
> <[hidden email]>
> *Elküldve:* 2017. november 28. 13:36
> *Címzett:* [hidden email]
> *Tárgy:* [OpenCV] Assertion failed (scn==3 || scn==4) cvtcolor line
> 3737. [2 Attachments]
> [Attachment(s) <#x_TopText> from [hidden email]
> [OpenCV] included below]
>
> Hi, i converting webcam video to grayscale .But i found
> error Assertion failed (scn==3 || scn==4) cvtcolor line 3737. code
> work well for images .But not working for ny type video.And i cant
> open avi files and found error
>
> Assertion failed (size.width>0 && size.height>0) in imshow line
> 261.Using opencv 2.4.9.
>
> Kindly solve my problems.I am new in c++ and opencv and also in
> programing.
>
>
>

--
   Leonardo Bocchi                              [hidden email]
   Dept. of Information Engineering             Tel. +39 055 2758 538
   University of Florence

Reply | Threaded
Open this post in threaded view
|

Re: Assertion failed (scn==3 || scn==4) cvtcolor line 3737.

muhammadjahanzaibkhan89
sir thanku for respons.i solve my problem but now i found another problem when i run the code frame is become black for all time. This is my code.
 #include "opencv2/objdetect/objdetect.hpp" #include "opencv2/highgui/highgui.hpp" #include "opencv2/imgproc/imgproc.hpp"
 #include <iostream> #include <stdio.h>
 using namespace std; using namespace cv;
 /** Function Headers */ void detectAndDisplay( Mat frame );
 /** Global variables */ String face_cascade_name = "haarcascade_frontalface_alt.xml"; String eyes_cascade_name = "haarcascade_eye_tree_eyeglasses.xml"; CascadeClassifier face_cascade; CascadeClassifier eyes_cascade; string window_name = "Capture - Face detection"; RNG rng(12345);
 /** @function main */ int main( int argc, const char** argv ) {   CvCapture* capture;   Mat frame;
   //-- 1. Load the cascades   if( !face_cascade.load( face_cascade_name ) ){ printf("--(!)Error loading\n"); return -1; };   if( !eyes_cascade.load( eyes_cascade_name ) ){ printf("--(!)Error loading\n"); return -1; };
   //-- 2. Read the video stream   capture = cvCaptureFromCAM( -1 );   if( capture )   {     while( true )     {   frame = cvQueryFrame( capture );
   //-- 3. Apply the classifier to the frame       if( !frame.empty() )       { detectAndDisplay( frame ); }       else       { printf(" --(!) No captured frame -- Break!"); break; }
       int c = waitKey(10);       if( (char)c == 'c' ) { break; }      }   }   return 0; }
/** @function detectAndDisplay */void detectAndDisplay( Mat frame ){  std::vector<Rect> faces;  Mat frame_gray;
  cvtColor( frame, frame_gray, CV_BGR2GRAY );  equalizeHist( frame_gray, frame_gray );
  //-- Detect faces  face_cascade.detectMultiScale( frame_gray, faces, 1.1, 2, 0|CV_HAAR_SCALE_IMAGE, Size(30, 30) );
  for( size_t i = 0; i < faces.size(); i++ )  {    Point center( faces[i].x + faces[i].width*0.5, faces[i].y + faces[i].height*0.5 );    ellipse( frame, center, Size( faces[i].width*0.5, faces[i].height*0.5), 0, 0, 360, Scalar( 255, 0, 255 ), 4, 8, 0 );
    Mat faceROI = frame_gray( faces[i] );    std::vector<Rect> eyes;
    //-- In each face, detect eyes    eyes_cascade.detectMultiScale( faceROI, eyes, 1.1, 2, 0 |CV_HAAR_SCALE_IMAGE, Size(30, 30) );
    for( size_t j = 0; j < eyes.size(); j++ )     {       Point center( faces[i].x + eyes[j].x + eyes[j].width*0.5, faces[i].y + eyes[j].y + eyes[j].height*0.5 );       int radius = cvRound( (eyes[j].width + eyes[j].height)*0.25 );       circle( frame, center, radius, Scalar( 255, 0, 0 ), 4, 8, 0 );     }  }  //-- Show what you got  imshow( window_name, frame ); }
 

    On Tuesday, November 28, 2017 5:58 AM, "Leonardo Bocchi [hidden email] [OpenCV]" <[hidden email]> wrote:
 

      Hi, it could be also that your video is not in colour. scn == 3 or scn == 4 means an RGB (or RGBA) video. In case it is a grayscale, you have scn = 1 and the assertion fails. Leonardo
 
 On 28/11/2017 12:51, Fábián Kristóf - Szabolcs [hidden email] [OpenCV] wrote:
 
       Hi,
  I think you are trying to process an empty frame. You should add this check before converting your image:
  //image is a cv::Mat here if (!image.empty()) {     //convert }
  Bests,
  Fabian
 
   Feladó: [hidden email] <[hidden email]>, meghatalmazó: [hidden email] [OpenCV] <[hidden email]>
 Elküldve: 2017. november 28. 13:36
 Címzett: [hidden email]
 Tárgy: [OpenCV] Assertion failed (scn==3 || scn==4) cvtcolor line 3737. [2 Attachments]        [Attachment(s) from [hidden email] [OpenCV] included below] Hi, i converting webcam video to grayscale .But i found error Assertion failed (scn==3 || scn==4) cvtcolor line 3737. code work well for images .But not working for ny type video.And  i cant open avi files and found error  Assertion failed (size.width>0 && size.height>0) in imshow line 261.Using opencv 2.4.9.
 
  Kindly solve my problems.I am new in c++ and opencv and also in programing.
 
         
 
 --
  Leonardo Bocchi                              [hidden email]
  Dept. of Information Engineering             Tel. +39 055 2758 538
  University of Florence                   #yiv5891285612 #yiv5891285612 -- #yiv5891285612ygrp-mkp {border:1px solid #d8d8d8;font-family:Arial;margin:10px 0;padding:0 10px;}#yiv5891285612 #yiv5891285612ygrp-mkp hr {border:1px solid #d8d8d8;}#yiv5891285612 #yiv5891285612ygrp-mkp #yiv5891285612hd {color:#628c2a;font-size:85%;font-weight:700;line-height:122%;margin:10px 0;}#yiv5891285612 #yiv5891285612ygrp-mkp #yiv5891285612ads {margin-bottom:10px;}#yiv5891285612 #yiv5891285612ygrp-mkp .yiv5891285612ad {padding:0 0;}#yiv5891285612 #yiv5891285612ygrp-mkp .yiv5891285612ad p {margin:0;}#yiv5891285612 #yiv5891285612ygrp-mkp .yiv5891285612ad a {color:#0000ff;text-decoration:none;}#yiv5891285612 #yiv5891285612ygrp-sponsor #yiv5891285612ygrp-lc {font-family:Arial;}#yiv5891285612 #yiv5891285612ygrp-sponsor #yiv5891285612ygrp-lc #yiv5891285612hd {margin:10px 0px;font-weight:700;font-size:78%;line-height:122%;}#yiv5891285612 #yiv5891285612ygrp-sponsor #yiv5891285612ygrp-lc .yiv5891285612ad {margin-bottom:10px;padding:0 0;}#yiv5891285612 #yiv5891285612actions {font-family:Verdana;font-size:11px;padding:10px 0;}#yiv5891285612 #yiv5891285612activity {background-color:#e0ecee;float:left;font-family:Verdana;font-size:10px;padding:10px;}#yiv5891285612 #yiv5891285612activity span {font-weight:700;}#yiv5891285612 #yiv5891285612activity span:first-child {text-transform:uppercase;}#yiv5891285612 #yiv5891285612activity span a {color:#5085b6;text-decoration:none;}#yiv5891285612 #yiv5891285612activity span span {color:#ff7900;}#yiv5891285612 #yiv5891285612activity span .yiv5891285612underline {text-decoration:underline;}#yiv5891285612 .yiv5891285612attach {clear:both;display:table;font-family:Arial;font-size:12px;padding:10px 0;width:400px;}#yiv5891285612 .yiv5891285612attach div a {text-decoration:none;}#yiv5891285612 .yiv5891285612attach img {border:none;padding-right:5px;}#yiv5891285612 .yiv5891285612attach label {display:block;margin-bottom:5px;}#yiv5891285612 .yiv5891285612attach label a {text-decoration:none;}#yiv5891285612 blockquote {margin:0 0 0 4px;}#yiv5891285612 .yiv5891285612bold {font-family:Arial;font-size:13px;font-weight:700;}#yiv5891285612 .yiv5891285612bold a {text-decoration:none;}#yiv5891285612 dd.yiv5891285612last p a {font-family:Verdana;font-weight:700;}#yiv5891285612 dd.yiv5891285612last p span {margin-right:10px;font-family:Verdana;font-weight:700;}#yiv5891285612 dd.yiv5891285612last p span.yiv5891285612yshortcuts {margin-right:0;}#yiv5891285612 div.yiv5891285612attach-table div div a {text-decoration:none;}#yiv5891285612 div.yiv5891285612attach-table {width:400px;}#yiv5891285612 div.yiv5891285612file-title a, #yiv5891285612 div.yiv5891285612file-title a:active, #yiv5891285612 div.yiv5891285612file-title a:hover, #yiv5891285612 div.yiv5891285612file-title a:visited {text-decoration:none;}#yiv5891285612 div.yiv5891285612photo-title a, #yiv5891285612 div.yiv5891285612photo-title a:active, #yiv5891285612 div.yiv5891285612photo-title a:hover, #yiv5891285612 div.yiv5891285612photo-title a:visited {text-decoration:none;}#yiv5891285612 div#yiv5891285612ygrp-mlmsg #yiv5891285612ygrp-msg p a span.yiv5891285612yshortcuts {font-family:Verdana;font-size:10px;font-weight:normal;}#yiv5891285612 .yiv5891285612green {color:#628c2a;}#yiv5891285612 .yiv5891285612MsoNormal {margin:0 0 0 0;}#yiv5891285612 o {font-size:0;}#yiv5891285612 #yiv5891285612photos div {float:left;width:72px;}#yiv5891285612 #yiv5891285612photos div div {border:1px solid #666666;min-height:62px;overflow:hidden;width:62px;}#yiv5891285612 #yiv5891285612photos div label {color:#666666;font-size:10px;overflow:hidden;text-align:center;white-space:nowrap;width:64px;}#yiv5891285612 #yiv5891285612reco-category {font-size:77%;}#yiv5891285612 #yiv5891285612reco-desc {font-size:77%;}#yiv5891285612 .yiv5891285612replbq {margin:4px;}#yiv5891285612 #yiv5891285612ygrp-actbar div a:first-child {margin-right:2px;padding-right:5px;}#yiv5891285612 #yiv5891285612ygrp-mlmsg {font-size:13px;font-family:Arial, helvetica, clean, sans-serif;}#yiv5891285612 #yiv5891285612ygrp-mlmsg table {font-size:inherit;font:100%;}#yiv5891285612 #yiv5891285612ygrp-mlmsg select, #yiv5891285612 input, #yiv5891285612 textarea {font:99% Arial, Helvetica, clean, sans-serif;}#yiv5891285612 #yiv5891285612ygrp-mlmsg pre, #yiv5891285612 code {font:115% monospace;}#yiv5891285612 #yiv5891285612ygrp-mlmsg * {line-height:1.22em;}#yiv5891285612 #yiv5891285612ygrp-mlmsg #yiv5891285612logo {padding-bottom:10px;}#yiv5891285612 #yiv5891285612ygrp-msg p a {font-family:Verdana;}#yiv5891285612 #yiv5891285612ygrp-msg p#yiv5891285612attach-count span {color:#1E66AE;font-weight:700;}#yiv5891285612 #yiv5891285612ygrp-reco #yiv5891285612reco-head {color:#ff7900;font-weight:700;}#yiv5891285612 #yiv5891285612ygrp-reco {margin-bottom:20px;padding:0px;}#yiv5891285612 #yiv5891285612ygrp-sponsor #yiv5891285612ov li a {font-size:130%;text-decoration:none;}#yiv5891285612 #yiv5891285612ygrp-sponsor #yiv5891285612ov li {font-size:77%;list-style-type:square;padding:6px 0;}#yiv5891285612 #yiv5891285612ygrp-sponsor #yiv5891285612ov ul {margin:0;padding:0 0 0 8px;}#yiv5891285612 #yiv5891285612ygrp-text {font-family:Georgia;}#yiv5891285612 #yiv5891285612ygrp-text p {margin:0 0 1em 0;}#yiv5891285612 #yiv5891285612ygrp-text tt {font-size:120%;}#yiv5891285612 #yiv5891285612ygrp-vital ul li:last-child {border-right:none !important;}#yiv5891285612

   
Reply | Threaded
Open this post in threaded view
|

Re: Assertion failed (scn==3 || scn==4) cvtcolor line 3737.

Fábián Kristóf - Szabolcs
This code is using the C API, the previous one was using the C++ one..

There must be something with your algorihm now..

________________________________
Feladó: [hidden email] <[hidden email]>, meghatalmazó: muhammad jahanzaib khan [hidden email] [OpenCV] <[hidden email]>
Elküldve: 2017. november 28. 16:07
Címzett: [hidden email]
Tárgy: Re: [OpenCV] Assertion failed (scn==3 || scn==4) cvtcolor line 3737.



sir thanku for respons.i solve my problem but now i found another problem when i run the code frame is become black for all time.
This is my code.

 #include "opencv2/objdetect/objdetect.hpp"
 #include "opencv2/highgui/highgui.hpp"
 #include "opencv2/imgproc/imgproc.hpp"

 #include <iostream>
 #include <stdio.h>

 using namespace std;
 using namespace cv;

 /** Function Headers */
 void detectAndDisplay( Mat frame );

 /** Global variables */
 String face_cascade_name = "haarcascade_frontalface_alt.xml";
 String eyes_cascade_name = "haarcascade_eye_tree_eyeglasses.xml";
 CascadeClassifier face_cascade;
 CascadeClassifier eyes_cascade;
 string window_name = "Capture - Face detection";
 RNG rng(12345);

 /** @function main */
 int main( int argc, const char** argv )
 {
   CvCapture* capture;
   Mat frame;

   //-- 1. Load the cascades
   if( !face_cascade.load( face_cascade_name ) ){ printf("--(!)Error loading\n"); return -1; };
   if( !eyes_cascade.load( eyes_cascade_name ) ){ printf("--(!)Error loading\n"); return -1; };

   //-- 2. Read the video stream
   capture = cvCaptureFromCAM( -1 );
   if( capture )
   {
     while( true )
     {
   frame = cvQueryFrame( capture );

   //-- 3. Apply the classifier to the frame
       if( !frame.empty() )
       { detectAndDisplay( frame ); }
       else
       { printf(" --(!) No captured frame -- Break!"); break; }

       int c = waitKey(10);
       if( (char)c == 'c' ) { break; }
      }
   }
   return 0;
 }

/** @function detectAndDisplay */
void detectAndDisplay( Mat frame )
{
  std::vector<Rect> faces;
  Mat frame_gray;

  cvtColor( frame, frame_gray, CV_BGR2GRAY );
  equalizeHist( frame_gray, frame_gray );

  //-- Detect faces
  face_cascade.detectMultiScale( frame_gray, faces, 1.1, 2, 0|CV_HAAR_SCALE_IMAGE, Size(30, 30) );

  for( size_t i = 0; i < faces.size(); i++ )
  {
    Point center( faces[i].x + faces[i].width*0.5, faces[i].y + faces[i].height*0.5 );
    ellipse( frame, center, Size( faces[i].width*0.5, faces[i].height*0.5), 0, 0, 360, Scalar( 255, 0, 255 ), 4, 8, 0 );

    Mat faceROI = frame_gray( faces[i] );
    std::vector<Rect> eyes;

    //-- In each face, detect eyes
    eyes_cascade.detectMultiScale( faceROI, eyes, 1.1, 2, 0 |CV_HAAR_SCALE_IMAGE, Size(30, 30) );

    for( size_t j = 0; j < eyes.size(); j++ )
     {
       Point center( faces[i].x + eyes[j].x + eyes[j].width*0.5, faces[i].y + eyes[j].y + eyes[j].height*0.5 );
       int radius = cvRound( (eyes[j].width + eyes[j].height)*0.25 );
       circle( frame, center, radius, Scalar( 255, 0, 0 ), 4, 8, 0 );
     }
  }
  //-- Show what you got
  imshow( window_name, frame );
 }



On Tuesday, November 28, 2017 5:58 AM, "Leonardo Bocchi [hidden email] [OpenCV]" <[hidden email]> wrote:



Hi, it could be also that your video is not in colour.
scn == 3 or scn == 4 means an RGB (or RGBA) video. In case it is a grayscale, you have scn = 1 and the assertion fails.
Leonardo


On 28/11/2017 12:51, Fábián Kristóf - Szabolcs [hidden email]<mailto:[hidden email]> [OpenCV] wrote:

Hi,

I think you are trying to process an empty frame. You should add this check before converting your image:

//image is a cv::Mat here
if (!image.empty()) {
    //convert
}

Bests,

Fabian


________________________________
Feladó: [hidden email]<mailto:[hidden email]> <[hidden email]><mailto:[hidden email]>, meghatalmazó: [hidden email]<mailto:[hidden email]> [OpenCV] <[hidden email]><mailto:[hidden email]>
Elküldve: 2017. november 28. 13:36
Címzett: [hidden email]<mailto:[hidden email]>
Tárgy: [OpenCV] Assertion failed (scn==3 || scn==4) cvtcolor line 3737. [2 Attachments]


[Attachment(s)<https://mail.yahoo.com/?.src=ym&soc_src=mail&soc_trk=ma#x_TopText> from [hidden email]<mailto:[hidden email]> [OpenCV] included below]
Hi, i converting webcam video to grayscale .But i found error Assertion failed (scn==3 || scn==4) cvtcolor line 3737. code work well for images .But not working for ny type video.And i cant open avi files and found error
Assertion failed (size.width>0 && size.height>0) in imshow line 261.Using opencv 2.4.9.

Kindly solve my problems.I am new in c++ and opencv and also in programing.




--
  Leonardo Bocchi                              [hidden email]<mailto:[hidden email]>
  Dept. of Information Engineering             Tel. +39 055 2758 538
  University of Florence




Reply | Threaded
Open this post in threaded view
|

Re: Assertion failed (scn==3 || scn==4) cvtcolor line 3737.

muhammadjahanzaibkhan89
yes in this code VideoCapture is change.But now i solve it. in 1st code we tracking object and in this code we detecting faces and eyes.Both things are use in program.
 

 But i face the problem from 1 week is that saved AVI files are not play and not open if i use this chwck
   if (!frame.empty()) { return -1;}
 

 it return -1.  
 i open capture lik this and avi file in the same folder .
 VideoCapture capture("green.avi");

 
 kindly solve my problem.
 

 and some thing more is this some videos play but mostaly not open.
Reply | Threaded
Open this post in threaded view
|

Re: Assertion failed (scn==3 || scn==4) cvtcolor line 3737.

Fábián Kristóf - Szabolcs
Don't return if it was an empty frame, just say continue; and you are doing it wrong, you quit it the frame was good (not empty), so:


if (frame.empty())

     continue;


________________________________
Feladó: [hidden email] <[hidden email]>, meghatalmazó: [hidden email] [OpenCV] <[hidden email]>
Elküldve: 2017. november 28. 16:50
Címzett: [hidden email]
Tárgy: Re: [OpenCV] Assertion failed (scn==3 || scn==4) cvtcolor line 3737.



yes in this code VideoCapture is change.But now i solve it.

in 1st code we tracking object and in this code we detecting faces and eyes.Both things are use in program.

But i face the problem from 1 week is that saved AVI files are not play and not open if i use this chwck
  if (!frame.empty()) { return -1;}

it return -1.
i open capture lik this and avi file in the same folder .
VideoCapture capture("green.avi");

kindly solve my problem.

and some thing more is this some videos play but mostaly not open.


Reply | Threaded
Open this post in threaded view
|

Re: Assertion failed (scn==3 || scn==4) cvtcolor line 3737.

muhammadjahanzaibkhan89
sir i have problem in line "if(capture.isOpened())"  . if we take file addres capture is not open but it works for webcam when we put "VideoCapture capture(0);"

int main( int argc, const char** argv ) {   VideoCapture capture("768x576.avi");   Mat frame;
   //-- 1. Load the cascades   if( !face_cascade.load( face_cascade_name ) ){ printf("--(!)Error loading\n"); return -1; };   if( !eyes_cascade.load( eyes_cascade_name ) ){ printf("--(!)Error loading\n"); return -1; };
   //-- 2. Read the video stream
  if (capture.isOpened())   {     while( true )     {   capture.read(frame);if (frame.empty())                  continue;   //-- 3. Apply the classifier to the frame       if( !frame.empty() )       { detectAndDisplay( frame ); }       else       { printf(" --(!) No captured frame -- Break!"); break; }
       int c = waitKey(10);       if( (char)c == 'c' ) { break; }      }   }   return 0; }

    On Tuesday, November 28, 2017 7:01 AM, "Fábián Kristóf - Szabolcs [hidden email] [OpenCV]" <[hidden email]> wrote:
 

     Don't return if it was an empty frame, just say continue; and you are doing it wrong, you quit it the frame was good (not empty), so:
if (frame.empty())      continue;

Feladó: [hidden email] <[hidden email]>, meghatalmazó: [hidden email] [OpenCV] <[hidden email]>
Elküldve: 2017. november 28. 16:50
Címzett: [hidden email]
Tárgy: Re: [OpenCV] Assertion failed (scn==3 || scn==4) cvtcolor line 3737.  yes in this code VideoCapture is change.But now i solve it.in 1st code we tracking object and in this code we detecting faces and eyes.Both things are use in program.
But i face the problem from 1 week is that saved AVI files are not play and not open if i use this chwck  if (!frame.empty()) { return -1;}
it return -1.  i open capture lik this and avi file in the same folder .VideoCapture capture("green.avi");
 kindly solve my problem.
and some thing more is this some videos play but mostaly not open.  #yiv6957497272 #yiv6957497272 -- #yiv6957497272ygrp-mkp {border:1px solid #d8d8d8;font-family:Arial;margin:10px 0;padding:0 10px;}#yiv6957497272 #yiv6957497272ygrp-mkp hr {border:1px solid #d8d8d8;}#yiv6957497272 #yiv6957497272ygrp-mkp #yiv6957497272hd {color:#628c2a;font-size:85%;font-weight:700;line-height:122%;margin:10px 0;}#yiv6957497272 #yiv6957497272ygrp-mkp #yiv6957497272ads {margin-bottom:10px;}#yiv6957497272 #yiv6957497272ygrp-mkp .yiv6957497272ad {padding:0 0;}#yiv6957497272 #yiv6957497272ygrp-mkp .yiv6957497272ad p {margin:0;}#yiv6957497272 #yiv6957497272ygrp-mkp .yiv6957497272ad a {color:#0000ff;text-decoration:none;}#yiv6957497272 #yiv6957497272ygrp-sponsor #yiv6957497272ygrp-lc {font-family:Arial;}#yiv6957497272 #yiv6957497272ygrp-sponsor #yiv6957497272ygrp-lc #yiv6957497272hd {margin:10px 0px;font-weight:700;font-size:78%;line-height:122%;}#yiv6957497272 #yiv6957497272ygrp-sponsor #yiv6957497272ygrp-lc .yiv6957497272ad {margin-bottom:10px;padding:0 0;}#yiv6957497272 #yiv6957497272actions {font-family:Verdana;font-size:11px;padding:10px 0;}#yiv6957497272 #yiv6957497272activity {background-color:#e0ecee;float:left;font-family:Verdana;font-size:10px;padding:10px;}#yiv6957497272 #yiv6957497272activity span {font-weight:700;}#yiv6957497272 #yiv6957497272activity span:first-child {text-transform:uppercase;}#yiv6957497272 #yiv6957497272activity span a {color:#5085b6;text-decoration:none;}#yiv6957497272 #yiv6957497272activity span span {color:#ff7900;}#yiv6957497272 #yiv6957497272activity span .yiv6957497272underline {text-decoration:underline;}#yiv6957497272 .yiv6957497272attach {clear:both;display:table;font-family:Arial;font-size:12px;padding:10px 0;width:400px;}#yiv6957497272 .yiv6957497272attach div a {text-decoration:none;}#yiv6957497272 .yiv6957497272attach img {border:none;padding-right:5px;}#yiv6957497272 .yiv6957497272attach label {display:block;margin-bottom:5px;}#yiv6957497272 .yiv6957497272attach label a {text-decoration:none;}#yiv6957497272 blockquote {margin:0 0 0 4px;}#yiv6957497272 .yiv6957497272bold {font-family:Arial;font-size:13px;font-weight:700;}#yiv6957497272 .yiv6957497272bold a {text-decoration:none;}#yiv6957497272 dd.yiv6957497272last p a {font-family:Verdana;font-weight:700;}#yiv6957497272 dd.yiv6957497272last p span {margin-right:10px;font-family:Verdana;font-weight:700;}#yiv6957497272 dd.yiv6957497272last p span.yiv6957497272yshortcuts {margin-right:0;}#yiv6957497272 div.yiv6957497272attach-table div div a {text-decoration:none;}#yiv6957497272 div.yiv6957497272attach-table {width:400px;}#yiv6957497272 div.yiv6957497272file-title a, #yiv6957497272 div.yiv6957497272file-title a:active, #yiv6957497272 div.yiv6957497272file-title a:hover, #yiv6957497272 div.yiv6957497272file-title a:visited {text-decoration:none;}#yiv6957497272 div.yiv6957497272photo-title a, #yiv6957497272 div.yiv6957497272photo-title a:active, #yiv6957497272 div.yiv6957497272photo-title a:hover, #yiv6957497272 div.yiv6957497272photo-title a:visited {text-decoration:none;}#yiv6957497272 div#yiv6957497272ygrp-mlmsg #yiv6957497272ygrp-msg p a span.yiv6957497272yshortcuts {font-family:Verdana;font-size:10px;font-weight:normal;}#yiv6957497272 .yiv6957497272green {color:#628c2a;}#yiv6957497272 .yiv6957497272MsoNormal {margin:0 0 0 0;}#yiv6957497272 o {font-size:0;}#yiv6957497272 #yiv6957497272photos div {float:left;width:72px;}#yiv6957497272 #yiv6957497272photos div div {border:1px solid #666666;min-height:62px;overflow:hidden;width:62px;}#yiv6957497272 #yiv6957497272photos div label {color:#666666;font-size:10px;overflow:hidden;text-align:center;white-space:nowrap;width:64px;}#yiv6957497272 #yiv6957497272reco-category {font-size:77%;}#yiv6957497272 #yiv6957497272reco-desc {font-size:77%;}#yiv6957497272 .yiv6957497272replbq {margin:4px;}#yiv6957497272 #yiv6957497272ygrp-actbar div a:first-child {margin-right:2px;padding-right:5px;}#yiv6957497272 #yiv6957497272ygrp-mlmsg {font-size:13px;font-family:Arial, helvetica, clean, sans-serif;}#yiv6957497272 #yiv6957497272ygrp-mlmsg table {font-size:inherit;font:100%;}#yiv6957497272 #yiv6957497272ygrp-mlmsg select, #yiv6957497272 input, #yiv6957497272 textarea {font:99% Arial, Helvetica, clean, sans-serif;}#yiv6957497272 #yiv6957497272ygrp-mlmsg pre, #yiv6957497272 code {font:115% monospace;}#yiv6957497272 #yiv6957497272ygrp-mlmsg * {line-height:1.22em;}#yiv6957497272 #yiv6957497272ygrp-mlmsg #yiv6957497272logo {padding-bottom:10px;}#yiv6957497272 #yiv6957497272ygrp-msg p a {font-family:Verdana;}#yiv6957497272 #yiv6957497272ygrp-msg p#yiv6957497272attach-count span {color:#1E66AE;font-weight:700;}#yiv6957497272 #yiv6957497272ygrp-reco #yiv6957497272reco-head {color:#ff7900;font-weight:700;}#yiv6957497272 #yiv6957497272ygrp-reco {margin-bottom:20px;padding:0px;}#yiv6957497272 #yiv6957497272ygrp-sponsor #yiv6957497272ov li a {font-size:130%;text-decoration:none;}#yiv6957497272 #yiv6957497272ygrp-sponsor #yiv6957497272ov li {font-size:77%;list-style-type:square;padding:6px 0;}#yiv6957497272 #yiv6957497272ygrp-sponsor #yiv6957497272ov ul {margin:0;padding:0 0 0 8px;}#yiv6957497272 #yiv6957497272ygrp-text {font-family:Georgia;}#yiv6957497272 #yiv6957497272ygrp-text p {margin:0 0 1em 0;}#yiv6957497272 #yiv6957497272ygrp-text tt {font-size:120%;}#yiv6957497272 #yiv6957497272ygrp-vital ul li:last-child {border-right:none !important;}#yiv6957497272

   
Reply | Threaded
Open this post in threaded view
|

Re: Assertion failed (scn==3 || scn==4) cvtcolor line 3737.

Fábián Kristóf - Szabolcs
I think you should use the absolute path, like "D:\Videos\video1.avi"


________________________________
Feladó: [hidden email] <[hidden email]>, meghatalmazó: muhammad jahanzaib khan [hidden email] [OpenCV] <[hidden email]>
Elküldve: 2017. november 28. 20:18
Címzett: [hidden email]
Tárgy: Re: [OpenCV] Assertion failed (scn==3 || scn==4) cvtcolor line 3737.



sir i have problem in line "if(capture.isOpened())"  . if we take file addres capture is not open but it works for webcam when we put "VideoCapture capture(0);"


int main( int argc, const char** argv )
 {
   VideoCapture capture("768x576.avi");
   Mat frame;

   //-- 1. Load the cascades
   if( !face_cascade.load( face_cascade_name ) ){ printf("--(!)Error loading\n"); return -1; };
   if( !eyes_cascade.load( eyes_cascade_name ) ){ printf("--(!)Error loading\n"); return -1; };

   //-- 2. Read the video stream

  if (capture.isOpened())
   {
     while( true )
     {
   capture.read(frame);
if (frame.empty())
                  continue;
   //-- 3. Apply the classifier to the frame
       if( !frame.empty() )
       { detectAndDisplay( frame ); }
       else
       { printf(" --(!) No captured frame -- Break!"); break; }

       int c = waitKey(10);
       if( (char)c == 'c' ) { break; }
      }
   }
   return 0;
 }


On Tuesday, November 28, 2017 7:01 AM, "Fábián Kristóf - Szabolcs [hidden email] [OpenCV]" <[hidden email]> wrote:



Don't return if it was an empty frame, just say continue; and you are doing it wrong, you quit it the frame was good (not empty), so:

if (frame.empty())
     continue;


________________________________
Feladó: [hidden email] <[hidden email]>, meghatalmazó: [hidden email] [OpenCV] <[hidden email]>
Elküldve: 2017. november 28. 16:50
Címzett: [hidden email]
Tárgy: Re: [OpenCV] Assertion failed (scn==3 || scn==4) cvtcolor line 3737.


yes in this code VideoCapture is change.But now i solve it.
in 1st code we tracking object and in this code we detecting faces and eyes.Both things are use in program.

But i face the problem from 1 week is that saved AVI files are not play and not open if i use this chwck
  if (!frame.empty()) { return -1;}

it return -1.
i open capture lik this and avi file in the same folder .
VideoCapture capture("green.avi");

kindly solve my problem.

and some thing more is this some videos play but mostaly not open.